【问题标题】:Facebook SDK 3.1 error when posting from iOS app从 iOS 应用发布时出现 Facebook SDK 3.1 错误
【发布时间】:2013-09-10 21:05:24
【问题描述】:

我的 iOS 应用程序遇到以下问题:

  1. 在发布到用户朋友的墙上时,使用 iOS 应用程序我收到错误“com.facebook.sdk error 5”。

  2. 每次我检查“FBSession.activeSession.isOpen”时,应用都会要求登录。

之前一切正常。但是由于我已经更改了我的应用 ID(因为现在我必须使用不同的 Facebook 应用)。我收到了错误。

我对此进行了一些研究,发现some solutions。我都试过了,但没有任何效果。

我编写了以下代码来登录 Facebook:

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
comingfromFB = YES;
NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"friends_birthday",
                        nil];

return [FBSession openActiveSessionWithReadPermissions:permissions
                                               allowLoginUI:allowLoginUI
                                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                                              [self sessionStateChanged:session state:state error:error];
                                          }];
}

以及发布故事的以下代码:

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];
}

当我运行应用程序时,我收到以下错误:

Error: HTTP status code: 403

2013-02-05 14:36:47.109 <appname>[1705:c07] Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xaa9af20 {com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 200;
            message = "(#200) The user hasn't authorized the application to perform this action";
            type = OAuthException;
        };
    };
    code = 403;
}, com.facebook.sdk:HTTPStatusCode=403}

请帮助我了解我哪里出错了。

我还向NSUserDefaults 添加了一些键值对。这可能是造成这种情况的原因吗?

谢谢。

【问题讨论】:

  • 我面临同样的问题。以下答案是否解决了您的问题?或者你是如何解决这个问题的。
  • @2vision2 下面提到的方法是正确的......但是当我只要求一个权限时,我通过在我的代码中要求两个权限“publish_stream”和“publish_actions”解决了我的发布问题我不能正常工作,我不知道为什么。

标签: iphone ios facebook facebook-graph-api nsuserdefaults


【解决方案1】:

当您第一次使用发布按钮显示视图时,也许您想检查会话是否打开并根据会话状态设置您的发布按钮标题。假设您的按钮最初具有“发布”标题:

[FBSession openActiveSessionWithAllowLoginUI: NO];

if (![FBSession.activeSession isOpen]) 
{
    [self setSendButtonTitle:NSLocalizedString(@"Log in",@"")];
}

然后将以下代码添加到您的发布按钮操作中:

- (void) send: (UIButton*) sender
{
    if (![FBSession.activeSession isOpen]) 
    {
        [FBSession openActiveSessionWithPublishPermissions: [NSArray arrayWithObjects: @"publish_stream", nil]
                                       defaultAudience: FBSessionDefaultAudienceEveryone
                                          allowLoginUI: YES

                              completionHandler: ^(FBSession *session,
                                                  FBSessionState status,
                                                  NSError *error) 
                              {
                                  if (error)
                                  {
                                      NSLog(@"error");
                                  } 
                                  else 
                                  {
                                      [FBSession setActiveSession:session];
                                      [self setSendButtonTitle: NSLocalizedString(@"Post",@"")];
                                  }
                              }];

        return;
    }

    // here comes the code you use for sending the message
}

因此,如果用户按下发送并且应用未授权,它将执行登录操作并将您的发布按钮标题从“登录”更改为“发布”。然后用户将能够通过再次按下按钮来发布消息。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2013-01-20
    • 1970-01-01
    相关资源
    最近更新 更多