从iOS应用程序更新的Facebook分数始终为零

时间:2014-10-28 13:10:58

标签: ios facebook facebook-graph-api

我使用以下代码更新我在Facebook上的游戏分数。对于要更新的​​新分数,条件是满足的,但是当我使用Graph API检查分数时,它始终为零。

    -(void)postScore:(int)currentScore
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               [NSString stringWithFormat:@"%d", currentScore], @"score",
                               nil];
    NSLog(@"Fetching current score");

    (FBSession.activeSession.isOpen) ? NSLog(@"session is OPEN") : NSLog(@"session is CLOSED");

    // Get the score, and only send the updated score if it's highter
    [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/scores", @"xxxx"] parameters:params HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (result && !error) {
            int nCurrentScore = [[[[result objectForKey:@"data"] objectAtIndex:0] objectForKey:@"score"] intValue];
            NSLog(@"Current score is %d", nCurrentScore);
            if (currentScore > nCurrentScore) {
               NSLog(@"Posting new score of %d", currentScore);
               [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/scores", @"xxxx"] parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                    NSLog(@"Score posted");
                }];
            }
            else {
                NSLog(@"Existing score is higher - not posting new score");
            }
        }

        if (error) {
            NSLog(@"the is an error");
        }
    }];
}

使用GET /USER_ID/scores检查分数,我得到:

    {
  "data": [
    {
      "user": {
        "id": "xxxx",
        "name": "My Name"
      },
      "score": 0,
      "application": {
        "name": "MyApp",
        "id": "xxxx"
      }
    }
  ]
}

对于POST /USER_ID/scores我得到:

    {
  "error": {
    "message": "Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
    "type": "GraphMethodException",
    "code": 100
  }
}

我在我的应用中请求facebook连接的权限:

        NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"email", @"public_profile",
                            @"user_friends",@"publish_actions", @"user_games_activity",@"friends_games_activity",
                            nil];

我将非常感谢您解决此问题的任何帮助。我已经有一段时间了。

0 个答案:

没有答案