我是 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... :)