我在使用SDK版本3.17时遇到了requestNewPublishPermissions的问题。Facebook文档建议先使用只读权限登录,然后再请求写入权限,这就是我正在尝试做的。我可以通过以下代码让用户成功登录:
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
// Handler for session state changes
// This method will be called EACH time the session state changes,
// also for intermediate states and NOT just when the session open
[self sessionStateChanged:session state:state error:error];
}];
当我想要发布到时间线时,我使用下面的代码请求扩展权限。应用程序将通过Facebook网页将其跳转到Safari。但是该网页没有要求写入权限,只是说该应用程序已经获得了授权。然后当我点击“确认”并控制返回应用程序时,我没有发布权限。请查看下面的“这就是它的结局!”。
我已经尝试过进入facebook.com并删除“应用程序”下已授予的权限,但没有任何效果。我还尝试过发布,但出现错误提示说我没有正确的权限。
有什么建议吗?
- (void) requestPublishPermission:(void (^)(void)) action
{
// Request publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
if ( [FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound )
{
// this is where it ends up!
}
else
{
// Permission granted, publish the story
action();
}
}
else
{
// permission denied, alert user
}
}];
}