I am currently learning PHP and I want to start incorporating Facebook basic elements such as friend lists etc just to do something more fun than building a web shop. However, I have followed the guides on Facebook and added an app and I got the canvas to display what I want, but how do I start getting data from Facebook? I have downloaded this https://github.com/facebook/php-sdk#readme and I added it to my project.
For example, how would I ask for permissions, pull data from my own profile? Do I need to parse JSON? Where is the API for the PHP SDK? This http://developers.facebook.com/docs/reference/api/ does not look like the get user id part here:
require 'php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
Any points in the right direction would be highly appreciated.
There is no need to parse JSON, you would have to go about doing an API request:
This would leave you with either a $user_profile containing every single element you’ve previously requested permission for (such as first_name, etc), put into an associative array (
$user_profilein this case).Obviously, you would first have to check for
getUser()‘s success or failure (if it returns 0, it failed), as the API call would behave as if you were logged out otherwise.