Facebook好友列表计数器0

时间:2015-07-25 05:50:23

标签: php facebook facebook-graph-api

我在开发者facebook中创建了测试应用程序。尝试使用App id和app Secret.i获取facebook好友列表已创建Follow代码

String county = address.getCounty().orElse("N/A");

最后在My localhost中运行代码,显示朋友列表零像这样

<?php

    //facebook application configuration
    $fbconfig['appid' ] = "xxxxxxxxxxxxxxxxxxxx";
    $fbconfig['secret'] = "xxxxxxxxxxxxxxxxxxxx";

    try{
        include_once ('.\facebook-php-sdk-master\src\facebook.php');
    }
    catch(Exception $o){

        print_r($o);

    }
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    $user       = $facebook->getUser();
    $loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'email'
            )
    );

    if ($user) {
      try {
        $user_profile = $facebook->api('/me');
        $user_friends = $facebook->api('/me/friends');
        $access_token = $facebook->getAccessToken();
      } catch (FacebookApiException $e) {
        d($e); 
        $user = null;
      }
    }

    if (!$user) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }

    $total_friends = count($user_friends['data']);
    echo 'Total friends: '.$total_friends.'.<br />';
    $start = 0;
    while ($start < $total_friends) {
        echo $user_friends['data'][$start]['name'];
        echo '<br />';
        $start++;
    }

?>

但我有2个朋友。请问如何解决我的问题?提前谢谢?

2 个答案:

答案 0 :(得分:2)

您需要使用user_friends权限进行授权。之后,您可以使用/me/friends来获取使用user_friends授权您的应用的朋友(仅限那些)。除了标记(taggable_friends)或邀请朋友加入画布游戏(invitable_friends)之外,不可能再吸引所有朋友。查看更改日志以了解更多更改:https://developers.facebook.com/docs/apps/changelog

有关更多信息,请查看此帖子的答案,来自Facebook员工:Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

答案 1 :(得分:-1)

facebook仅在两种情况下返回您的朋友列表。

  1. 您的应用必须属于游戏类别。
  2. 如果你的应用不属于游戏,那么它只会返回喜欢该特定应用的朋友列表。
  3. 在获取好友列表之前,请检查您的应用是否已获得Facebook的正确许可。