FBSession:尝试重新授权未开放会话的权限 [英] FBSession: an attempt was made reauthorize permissions on an unopened session

查看:114
本文介绍了FBSession:尝试重新授权未开放会话的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循教程
来实施在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
                                     }
                                 }];
}

与错误:错误:


domain = com.facebook.sdk,code = 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆