Skip to content

Instantly share code, notes, and snippets.

@ravikiranj
Created May 6, 2011 05:23
Show Gist options
  • Save ravikiranj/958483 to your computer and use it in GitHub Desktop.
Save ravikiranj/958483 to your computer and use it in GitHub Desktop.
Obtaining Facebook User's data via FB Graph API and FQL
<?php
try {
// Get UID of the user
$uid = $this->fb->getUser();
// Get basic info about the user
$me = $this->fb->api('/me');
// Get the user's facebook stream
$feed = $this->fb->api('/me/home');
// Obtain user's and his/her friend's basic information via FQL Multiquery
$streamQuery = <<<STREAMQUERY
{
"basicinfo": "SELECT uid,name,pic_square FROM user WHERE uid=me()",
"friendsinfo" : "SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
}
STREAMQUERY;
$streamParams = array(
'method' => 'fql.multiquery',
'queries' => $streamQuery
);
$streamResult = $this->fb->api($streamParams);
//Obtain user likes, interests, movies, music, books
$likes = $this->fb->api('/me/likes');
$interests = $this->fb->api('/me/interests');
$movies = $this->fb->api('/me/movies');
$music = $this->fb->api('/me/music');
$books = $this->fb->api('/me/books');
}catch(FacebookApiException $e) {
error_log($e);
//Session expired or user de-authenticated the app
$this->showConnectToFB(true);
}
?>
@samsms
Copy link

samsms commented Mar 30, 2022

ik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment