0

在我的应用程序中,我想在墙上贴一张图片,但我想我错过了一些东西。我做了很多研究,最终得到了那个代码。实际上它有时可以工作,但通常在代码运行时,因为没有具有 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");
                                             }
                                         }];
    }
4

1 回答 1

0

在代码的第一部分,当您请求新的发布权限时,您拥有 [NSArray arrayWithObject:@"publish_action"]....

如果我没记错的话,我认为应该是[NSArray arrayWithObject:@"publish_actions"]

这是来自 facebook 文档的代码片段 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
                           ...
                       }
        }];
    }
于 2013-07-03T14:57:37.043 回答