Created
May 6, 2011 05:23
-
-
Save ravikiranj/958483 to your computer and use it in GitHub Desktop.
Obtaining Facebook User's data via FB Graph API and FQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ik