Facebook api friends list

杀马特。学长 韩版系。学妹 提交于 2019-12-11 08:27:48

问题


I'm using Facebook's javascript SDK to inspect the friends list of users registered in my application.

I have this call:

     FB.getLoginStatus(function (response) {
        if (response.status == 'connected') {     
           FB.api('me/friends', { fields: 'id, first_name, picture', limit: 6 },function(response){
                  MY CODE TO VIEW FRIENDS PICTURE
           });
        }
        else{
                 CODE TO GET ACCESS_TOKEN
        }
  });

but in most of cases I get an api error like this:

response.error = {
message: unkown error,
code: undefined,
type: http,
subcode: undefined
}

I tested it with my account and it works fine, even if I change privacy permission as friend's sharing.

There is something wrong in my code?


回答1:


FB.api('me/friends', { fields: 'id, first_name,picture', limit: 6 },function(response){

    console.log(response);

  });

For more detail information use Facebook's graph API explore :Facebook Graph aPI




回答2:


Why don't you use an fql query with FB.api? It offers a great control.

The following FQL return (User ID, First Name and Picture of a friend who is using the application)

FB.api(
         {
           method: 'fql.query',
           query: 'SELECT uid,first_name,pic FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) and is_app_user limit 6',
           access_token: token
         }

Note: You would better use this condition

if (response && response.authResponse) {

Instead of:

if (response.status == 'connected') {

Regards,



来源:https://stackoverflow.com/questions/16060479/facebook-api-friends-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!