iRa*_*ium 16 permissions sdk facebook login ios
我无法使用facebook 3.1 ios sdk中的发布权限登录.
我的应用程序有一个共享视频的按钮,当用户点击它时,我想添加基本+发布权限.据我了解,我必须做两个电话 -
openActiveSessionWithReadPermissions, 然后reauthorizeWithPublishPermissions这是我现在使用的代码:
//Opens a Facebook session and optionally shows the login UX.
- (void)openSessionForReadPermissions
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
//this is called even from the reauthorizeWithPublishPermissions
if (state == FBSessionStateOpen && !error)
{
[self openSessionForPublishPermissions];
}
else if (state == FBSessionStateClosedLoginFailed)
{
[FBSession.activeSession closeAndClearTokenInformation];
[[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification object:session];
}
}];
}
-(void)openSessionForPublishPermissions
{
NSArray* permissions = [NSArray arrayWithObject:@"publish_stream"];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:
^(FBSession *session, NSError *error)
{
if (!error)
{
[[NSNotificationCenter defaultCenter]
postNotificationName:FBLoginSuccessNotification
object:session];
}
else
{
[[NSNotificationCenter defaultCenter]
postNotificationName:FBLoginErrorNotification
object:session];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
我看到openSessionForReadPermissions中的块被调用两次(一次使用FBSessionStateOpen,一次使用来自openSessionForPublishPermissions调用的FBSessionStateOpenTokenExtended),并且在第一次尝试登录应用程序时获得ErrorReauthorizeFailedReasonUserCancelled(如果O之前删除了所有应用程序权限).
实现此登录的正确方法是什么?该应用程序不需要Facebook登录,除了这一功能,因此登录过程应该在同一个按钮上.
谢谢!
Ray*_*gan 26
我碰到了同样的问题.我发现的解决方案是将调用包装[self openSessionForPublishPermissions];在dispatch_async块中.
例:
dispatch_async(dispatch_get_current_queue(), ^{
[self openSessionForPublishPermissions];
});
Run Code Online (Sandbox Code Playgroud)
原因是重新授权的调用需要在调用openActiveSession ..的事件循环之后.
| 归档时间: |
|
| 查看次数: |
7232 次 |
| 最近记录: |