Facebook iOS 3.1 sdk登录发布权限回调 [英] Facebook iOS 3.1 sdk login with publish permission callbacks
问题描述
我的应用有一个分享视频的按钮,当用户点击我想添加基本的+发布权限。据了解,我必须打两个电话 -
-
openActiveSessionWithReadPermissions
,然后 -
reauthorizeWithPublishPermissions
我现在使用的代码:
//打开Facebook会话,并可选择显示登录UX。
- (void)openSessionForReadPermissions
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession * session,
FBSessionState状态,NSError *错误){
//甚至从reauthorizeWithPublishPermissions调用
if(state == FBSessionStateOpen&&!error)
{
[self openSessionForPublishPermissions];
}
else if(state == FBSessionStateClosedLoginFailed)
{
[FBSession.activeSession closeAndClearTokenInformation];
[[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification对象: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];
}
}];
}
我看到openSessionForReadPermissions中的块被调用两次(一次使用FBSessionStateOpen和一旦从OpenSessionForPublishPermissions调用的FBSessionStateOpenTokenExtended),并且当我第一次尝试登录到应用程序(如果O删除所有应用程序权限)时,我得到一个ErrorReauthorizeFailedReasonUserCancelled。
什么是正确的方式来实现这个登录?该应用程序不需要Facebook登录,除了此功能之外,所以登录过程应该在同一个按钮上。
谢谢!
我遇到同样的问题。我找到的解决方案是在dispatch_async块中打包调用 [self openSessionForPublishPermissions];
。
示例: / p>
dispatch_async(dispatch_get_current_queue(),^ {
[self openSessionForPublishPermissions];
});
原因是重新授权的调用需要在其中openActiveSession的事件循环之后。被称为。
I'm having trouble logging in with publish permissions in the facebook 3.1 ios sdk.
My app has a button to share a video, and when the user clicks it I want to add the basic + publish permission. As I understand, i have to do two calls -
openActiveSessionWithReadPermissions
, and thenreauthorizeWithPublishPermissions
Here's the code I'm using now:
//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];
}
}];
}
I see that the block in the openSessionForReadPermissions is called twice (once with FBSessionStateOpen and once with FBSessionStateOpenTokenExtended from the openSessionForPublishPermissions call), and I get a ErrorReauthorizeFailedReasonUserCancelled when first trying to login to the app (if O deleted all app permissions before).
What is the proper way to implement this login? The app does not require Facebook log-in, except for this one feature, so the login process should be on the same button push.
Thanks!
I ran across this same issue. The solution I found was wrapping the call to [self openSessionForPublishPermissions];
in a dispatch_async block.
Example:
dispatch_async(dispatch_get_current_queue(), ^{
[self openSessionForPublishPermissions];
});
The reason is that the call to reauthorize.. needs to be after the event loop of which openActiveSession.. is called.
这篇关于Facebook iOS 3.1 sdk登录发布权限回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!