2

我是 iOS 开发的新手,我已经成功集成了 facebook 登录等等......但是我的问题是 Score api。我可以阅读分数,但我似乎无法发布它,我拥有 publish_actions 权限,并且正在取回一个有效的 access_token。不确定是什么问题,这是我的代码 -

NSString *accessTokenToUse = [NSString stringWithFormat:@"%@",[self.facebook accessToken] ];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   //@"233", @"score",
                                   accessTokenToUse, @"access_token",
                                   nil];
    NSMutableDictionary *paramsB = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"233", @"score",
                                   accessTokenToUse, @"access_token",
                                   nil];
    NSLog(@"APP ACCESS TOKEN: %@",accessTokenToUse);

    [self.facebook requestWithGraphPath:@"me/scores" andParams:paramsB andHttpMethod:@"POST" andDelegate:self];
    [self.facebook requestWithGraphPath:@"APP_ID/scores" andParams:params andHttpMethod:@"GET" andDelegate:self];

***编辑 - 仍然不起作用

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"233", @"score", 
                               @"[APP_ACCESS_TOKEN (omitted for stackoverflow)]", @"access_token", nil];
[self.facebook requestWithGraphPath:@"/[userID]/scores" andParams:params andHttpMethod:@"POST" andDelegate:self];

编辑 - 已解决

所以基本上我是在传递正确的令牌,但是 facebook sdk 在 Facebook.m 中将它覆盖到用户的访问令牌。所以修复很简单 - 每当我需要传递应用程序的令牌时,我只需添加一个其他参数 < key=@"useAppToken" Value=@"yes" > 并在 Facebook.m 中添加一个 if 语句 isSessionValid -

- (FBRequest*)openUrl:(NSString *)url
           params:(NSMutableDictionary *)params
       httpMethod:(NSString *)httpMethod
         delegate:(id<FBRequestDelegate>)delegate {

NSLog(@"PARAMS BFORE: %@ ", params);
[params setValue:@"json" forKey:@"format"];
[params setValue:kSDK forKey:@"sdk"];
[params setValue:kSDKVersion forKey:@"sdk_version"];

if ([self isSessionValid]) {
    if ([params objectForKey:@"useAppToken"] == nil || [params objectForKey:@"useAppToken"] == @"no") {
        [params setValue:self.accessToken forKey:@"access_token"];
    }

}
NSLog(@"PARAMS AFTER: %@ ", params);
[self extendAccessTokenIfNeeded];

FBRequest* _request = [FBRequest getRequestWithParams:params
                                           httpMethod:httpMethod
                                             delegate:delegate
                                           requestURL:url];
[_requests addObject:_request];
[_request addObserver:self forKeyPath:requestFinishedKeyPath options:0    context:finishedContext];
[_request connect];
return _request;

}

请务必在此注释掉 NSLogs... :)

4

2 回答 2

1

分数只能使用应用程序发布access_token,而不能为用户发布(您可能正在使用它,可以阅读分数,但不允许您发布它们)。

引用分数文档

为用户创建或更新分数只要您有权限,您就可以通过向应用
发出HTTP POST请求来发布分数或用户。/USER_ID/scoresaccess_tokenpublish_actions

于 2012-06-12T09:09:46.457 回答
0

看起来这是一个错误:http: //developers.facebook.com/bugs/461900043821056

但是,如果您将应用程序设置更改为网络应用程序而不是本机应用程序,它将起作用。

于 2012-07-06T23:38:11.773 回答