2012-12-22 22 views
2

我设置以下权限,无论是在我的身边和应用的权限页面:
(注意‘read_stream’)Facebook的:返回“500(内部服务器错误),”为朋友信息请求

<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图形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/

相关问题