FBSDKGraphRequest响应问题 - 没有获得分数

时间:2015-07-29 09:13:03

标签: ios facebook facebook-graph-api facebook-sdk-4.x

我正在使用以下代码来获取我的Facebook朋友的游戏分数。

    -(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) {

    }];
}

并得到以下结合的回应

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

}

但这不是预期的反应。 我的预期格式正在关注

{
data =     (

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

}

任何人都可以帮助我得到正确答案吗?

4 个答案:

答案 0 :(得分:0)

看起来您正在使用Graph API v2.4。有了这个,你必须指定你想要返回的每个字段。请在此处查看我的答案:

您需要timestamp而不是/{app_id}/scores?fields=user,application,score我想如果您还想看到朋友的分数

或者,

/me/scores?fields=user,application,score

也应该有用

答案 1 :(得分:0)

使用以下代码解决。

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

答案 2 :(得分:0)

我们如何在android.i中做同样的问题在android中我使用以下代码

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
                        }

                    }
        }
    }
}

如何解决此问题

答案 3 :(得分:0)

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
                        }

                    }
        }
    }
}