iOS Facebook sdk-无法获取发布权限和发布状态
我一直在遵循Facebook的指南,并试图通过iOS应用程序更新状态。在尝试将我的状态更新到我的时间线时,我检查了我是否拥有发布权限,如果没有,则请求发布权限,代码如下: GraphViewController.m中的代码:iOS Facebook sdk-无法获取发布权限和发布状态,ios,facebook,facebook-graph-api,permissions,Ios,Facebook,Facebook Graph Api,Permissions,我一直在遵循Facebook的指南,并试图通过iOS应用程序更新状态。在尝试将我的状态更新到我的时间线时,我检查了我是否拥有发布权限,如果没有,则请求发布权限,代码如下: GraphViewController.m中的代码: - (IBAction)postClicked:(id)sender { if([self.status_input isFirstResponder]) [self.status_input resignFirstResponder]; if ([FBSess
- (IBAction)postClicked:(id)sender {
if([self.status_input isFirstResponder])
[self.status_input resignFirstResponder];
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
// No permissions found in session, ask for it
NSLog(@"No permission");
[FBSession.activeSession
requestNewPublishPermissions:
[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// If permissions granted, publish the story
[self postStatusWithGraphAPI];
}
}];
} else {
// If permissions present, publish the story
[self postStatusWithGraphAPI];
}
}
方法postStatusWithGraphAPI:
- (void) postStatusWithGraphAPI{
[FBRequestConnection startForPostStatusUpdate:@"User-generated status update."
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Status update posted successfully to Facebook
NSLog(@"result: %@", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"%@", error.description);
}
}];
}
此视图控制器不处理应用程序的facebook登录,该登录由另一个视图控制器(即MyViewController)处理。简而言之,流程是这样的:
我在另一个API(我想是Twitter)上也遇到过类似的问题,所以问题可能不完全相同,但我记得我通过使用预期的OAuth作用域重新发布应用程序机密来解决了我的问题。另外,请确保您已在Facebook开发者应用程序页面中指定了应用程序所需的所有作用域。@Romain:对不起,我是新手,您的意思是在Facebook开发者页面的“我的应用程序”页面中重置应用程序机密吗?至于权限范围,页面状态和评论中只列出了3个,分别是电子邮件、公共档案和用户朋友。而且似乎没有办法在那里添加额外的权限?忘记我之前的评论,它可能不适用于Facebook SDK。你的应用程序仍然处于开发者/沙盒模式吗?我在Facebook开发者网站()上读到,请求
publish\u actions
权限需要Facebook团队的审核。如果您的应用被视为“正在生产”,而不是处于沙箱模式,则拒绝您的新权限请求可能是正常的。此外,与您当前面临的问题无关,在If(!error)
块代码中,您不应该假设您成功地从用户那里获得了权限:他可能拒绝了请求,因此您需要通过执行类似于if([FBSession.activeSession.permissions indexOfObject:@“publish\u actions”]==NSNotFound){//未授予权限}的操作再次检查publish\u actions
{//your code}
。您有没有找到解决此问题的方法?