FBSDKGraphRequest Response Issue - Not getting scores

主宰稳场 提交于 2019-12-02 10:00:27

问题


I am using following code to get the game score of my facebook friend.

    -(void)GetFriendScore
{
    NSMutableDictionary* params =   [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     [NSString stringWithFormat:@"%@", [FBSDKAccessToken currentAccessToken]], @"access_token",
                                     nil];

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me/scores"
                                  parameters:params
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {

    }];
}

and got the response in following formate

{
data =     (
            {
            user =             {
                id = XYZ;
                name = "XYZ";
            };
            }
            );

}

but this is not expected response. my expected formate is following

{
data =     (

            {
            application =             {
                category = Games;
                id = XYZ;
                link = "https://www.facebook.com/games/?app_id=XYZ";
                name = "XYZ";
            };
            score = 2907;
            user =             {
                id = XYZ;
                name = "XYZ";
            };
            }
            );

}

can anyone please help me to get correct response ?


回答1:


Looks like you're using Graph API v2.4. With that, you'll have to specify each field you want to have returned. See my answer for a similar question here:

  • Graph API Score with GET method can't return score field

You need to request /{app_id}/scores?fields=user,application,score instead of /me/scores?fields=user,application,score I guess if you also want to see the friend's scores

See

  • https://developers.facebook.com/docs/graph-api/reference/v2.4/app/…

Alternatively,

/me?fields=scores{user,application,score},friends{scores{user,application,score}‌​}

should work as well




回答2:


Solved by using following code.

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:@"/me/scores?fields=user,application,score"
                              parameters:params
                              HTTPMethod:@"GET"];



回答3:


How we can do same in android.i have same problem in android i am using following code

request = new Request(Session.getActiveSession(), "/ "+"FB_ID"+"/scores?fields=user,application,score", param , HttpMethod.GET);
if(request!=null)
{
    request.setCallback(new Request.Callback()
    {
        public void onCompleted(Response response)
        {
                    if(response!=null)
                    {
                        GraphObject graphObject = response.getGraphObject();
                        if(graphObject==null)
                        {
                            //getting graphObject NULL
                        }

                    }
        }
    }
}

how to resolve this issue




回答4:


param.putString("fields", "user,application,score");
request = new Request(Session.getActiveSession(), "/me/scores", param , HttpMethod.GET);
if(request!=null)
{
    request.setCallback(new Request.Callback()
    {
        public void onCompleted(Response response)
        {
                    if(response!=null)
                    {
                        GraphObject graphObject = response.getGraphObject();
                        if(graphObject==null)
                        {
                            //Enjoy
                        }

                    }
        }
    }
}


来源:https://stackoverflow.com/questions/31696095/fbsdkgraphrequest-response-issue-not-getting-scores

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