我正在关注这个tutorial
在Facebook SDK 3.1上实现 View 预览文章,但是当我调用此方法时
...
// 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];
}
...
返回以下错误:
会发生什么事?谢谢!
编辑:
跑了我的 friend ,非常感谢,但是仍然有一个细节...当第一次发帖时,他要求授权应用程序时,我授权了这个秋天
/*
*在具有发布权限的情况下打开一个新 session
*/
[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
}
}];
}
错误:错误:
最佳答案
该错误表明未打开FBSession。因此,您应在尝试重新授权之前检查 session 是否已打开。
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 (请注意复数)。
关于ios - FBSession : an attempt was made reauthorize permissions on an unopened session,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14695312/