質問

Using Php can I get all my facebook friends who are greater than 25 years old. I have use the follwoing code but didn't get any success.

$api_key = '{APP-ID}';
$secret  = '{APP-SECRET}';

include_once 'facebook-php-sdk-master/src/facebook.php';

$facebook = new Facebook($api_key, $secret);
$user = $facebook->getUser(); 

if ($user) {
    $user_profile = $facebook->api('/me');
    $friends = $facebook->api('/me/friends');

    echo '<ul>';
    foreach ($friends["data"] as $value) {
        echo '<li>';
        echo '<div class="pic">';
        echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>';
        echo '</div>';
        echo '<div class="picName">'.$value["name"].'</div>'; 
        echo '</li>';
    }
    echo '</ul>';
}

Please help me.

役に立ちましたか?

解決

I don't know which tutorial you followed but that's the incorrect way of creating a Facebook object.

Replace your starting code with-

include_once 'facebook-php-sdk-master/src/facebook.php';

$config = array(
   'appId' => 'YOUR_APP_ID',
   'secret' => 'YOUR_APP_SECRET',
   'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);

$facebook = new Facebook($config);
$user = $facebook->getUser(); 

You must follow the official documentation of using the PHP SDK.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top