sabato 18 maggio 2013

Getting Array of Facebook friends with Php

Are you trying to create an array containing Facebook friends and their information with php but it does not come out?
Here is the guide for you.
Download the SDK for PHP from here: https://github.com/facebook/facebook-php-sdk;
Create a file LettoreAmici.php and paste this into this:
<?
require 'facebook-php-sdk-master/src/facebook.php';
$ app_id = 'xxxxxxxxxxxxxx';
$ app_secret = 'xxxxxxxxxxxx';
$ facebook = new Facebook (array (
'AppId' => $ app_id,
'Secret' => $ app_secret,
));
$ user = $ facebook-> getUser ();
if ($ user) {
try {
$ user_profile = $ facebook-> api ('me / friends');
print_r ($ user_profile);
} Catch (FacebookApiException $ e) {
error_log ($ e);
$ user = null;
}
Else {}
$ params = array (
'Scope' => 'user_birthday',
);
$ loginUrl = $ facebook-> getLoginUrl ($ params);
echo ("<script> top.location.href = '". $ loginUrl. "' </ script>");
}
?>
Replace the lines $ app_id = 'xxxxxxxxxxxxxx', and $ app_secret = 'xxxxxxxxxxxx', with your app-secret and once started the page you will have the array with the information of your friends in the variable $ user_profile, which will also be printed in video from the command print_r.

Nessun commento:

Posta un commento