【问题标题】:Facebook: Returns "500 (Internal Server Error)" for friends info requestFacebook:为好友信息请求返回“500(内部服务器错误)”
【发布时间】:2013-04-11 03:56:32
【问题描述】:

我已经在我这边和应用程序的权限页面上设置了以下权限:
(注意“read_stream”)

<fb:login-button autologoutlink="true" perms="read_stream, user_about_me, user_likes, user_location, user_birthday, user_education_history, user_work_history, friends_about_me, friends_likes, friends_location, friends_birthday, friends_education_history, friends_work_history"></fb:login-button>


请求用户的个人资料效果很好:

FB.api('/me/friends', {
            fields: "id,username,name,first_name,last_name,location,link,education,work,statuses.limit(1).fields(message)"
        }, function(res){
            console.log('FRIENDS', res.data);
        });


但是,为用户的朋友获取相同的信息是行不通的。
它给出“500(内部服务器错误)”,facebook 对象返回“未知错误”。

FB.api('/me/friends', {
            fields: "id,username,name,first_name,last_name,location,link,education,work,statuses.limit(1).fields(message)"
        }, function(res){
            console.log('FRIENDS', res.data);
        });



我已将问题追溯到我请求的字段。 statuses.limit(1).fields(message) 部分似乎是错误的来源,删除后 /me/friends 返回数据。
但我不明白错误的原因。

  1. 它适用于/me
  2. 根据 FB 文档,read_steam 应该同时用于用户状态和用户朋友的状态。
  3. 使用上述字段,API Explorer 可以毫无问题地获取我的朋友状态。

我做错了什么还是 FB Graph API 错误?

谢谢。

【问题讨论】:

    标签: facebook facebook-graph-api


    【解决方案1】:

    这里试试这个:

    $user = $facebook->getUser();
    if ($user){ 
               try {
                    $queries = array(
                                 array('method' => 'GET', 'relative_url' => '/'.$user),
                                 array('method' => 'GET', 'relative_url' => '/'.$user.'/friends', 'name' =>  'get-friends'),
                                 array('method' => 'GET','relative_url'  => '?ids={result=get-friends:$.data.*.id}'),
                                );
    
                                // POST your queries to the batch endpoint on the graph.
                                try{
                                    $batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
                                }catch(Exception $o){
                                        error_log($o);
                                }
                              } 
                            catch (FacebookApiException $e) {
                                error_log($e); //Checks if user is logged out and generate an exception if access token is invalid
                            }
                         }
                         else{
                                $params = array(
                                      'scope' => 'friends_birthday, friends_education_history, read_stream, read_friendlists, user_birthday,   //Requesting User Permissions through Facebook App
                                      'redirect_uri' => 'specify yours here' //User is redirected after Login
                                    );
    
                            } 
     $user_details = json_decode($batchResponse[0]['body'], true);// User Own Info
     $user_friends = json_decode($batchResponse[2]['body'], true);// User's Firend Info
    

    你会得到一个数组对象。

    或者您可以在这里使用 FQL:

    $friends = $facebook->api(array(
                                            'method' => 'fql.query',
                                            'query' => 'SELECT name, pic_big 
                                                 FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'
                                        ));
    

    https://developers.facebook.com/docs/reference/fql/friend/

    我正在做类似的事情,在这里:http://agbcorplegal.com/profile_filter/

    【讨论】:

      猜你喜欢
      • 2015-11-08
      • 1970-01-01
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多