在我的应用程序中,我想在墙上发布图像,但我想我会想念一些东西。我做了很多研究并最终得到了这些代码。实际上它有时工作但通常在代码运行时因为没有具有publish_action权限的会话,代码的第二部分正在工作但问题是我总是在第二部分得到错误日志,所以我不能继续......你呢知道为什么我无法打开具有发布权限的活动会话吗?
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_action"] defaultAudience:FBSessionDefaultAudienceOnlyMe
completionHandler:^(FBSession *session,NSError *error){
action();
}];
}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");
}
}];
}
答案 0 :(得分:0)
在您请求新的发布权限时,代码的第一部分
[NSArray arrayWithObject:@"publish_action"]
....
如果我没有错,我认为应该是[NSArray arrayWithObject:@"publish_actions"]
这是来自facebook docs的代码片段 https://developers.facebook.com/docs/technical-guides/iossdk/errors/
// Method that requests permissions needed to make the API call.
- (void)requestPermissionCallAPI {
[FBSession.activeSession
requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceEveryone
completionHandler:^(FBSession *session, NSError *error) {
if (error) {
// Handle new permissions request errors
[self handleRequestPermissionError:error];
} else {
// Make API call
...
}
}];
}