FBSession:尝试重新授权未打开会话的权限 [英] FBSession: an attempt was made reauthorize permissions on an unopened session
问题描述
我正在关注这个教程在 Facebook SDK 3.1 上实现视图预览帖子,但是当我调用此方法时...
I'm following this tutorial to implement the view preview post on Facebook SDK 3.1, but when I call this method ...
// Ask for publish_actions permissions in context
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
// No permissions found in session, ask for it
[FBSession.activeSession
reauthorizeWithPublishPermissions:
[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// If permissions granted, publish the story
[self publishStory];
}
}];
} else {
// If permissions present, publish the story
[self publishStory];
}
...
返回以下错误:
* 由于未捕获的异常com.facebook.sdk:InvalidOperationException"而终止应用程序,原因:FBSession:进行了尝试重新授权未打开会话的权限'
* Terminating app due to uncaught exception 'com.facebook.sdk: InvalidOperationException', reason: 'FBSession: an attempt was made reauthorize permissions on an unopened session'
到底发生了什么?谢谢!
What is happening can? Thank you!
跑了我的朋友,非常感谢,不过还是有细节...什么时候发帖他第一次要求授权申请我授权这个秋天的块
Ran my friend, thank you very much, but still have a detail ...When'll post the first time he asks to authorize the application I authorize this block of fall
/** 打开一个具有发布权限的新会话*/
/* * open a new session with publish permission */
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self publishStory];
}else{
NSLog(@"error");
//Here I get the error mentioned below
}
}];
}
出现错误:错误:
域 = com.facebook.sdk,代码 = 5
domain = com.facebook.sdk, code = 5
推荐答案
报错说FBSession没有打开.所以你应该在尝试重新授权之前检查会话是否打开.
The error says that the FBSession is not opened. so you should check if the session is opened before trying to reauthorize.
if ([[FBSession activeSession] isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self postPhoto];
}];
}else{
[self publishStory];
}
}else{
/*
* open a new session with publish permission
*/
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self publishStory];
}else{
NSLog(@"error");
}
}];
}
确保始终请求相同的权限,应该是 publish_actions(注意复数).
Make sure to consistently request for the same permissions which should be publish_actions (mind the plural).
这篇关于FBSession:尝试重新授权未打开会话的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!