2013-02-05 43 views
2

我面臨着以下問題,我的iOS應用:的Facebook SDK 3.1的錯誤從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。這可能是一個可能的原因嗎?

謝謝。

+0

正面臨同樣的問題。以下答案是否解決了您的問題?或者你是如何解決這個問題的。 – 2vision2

+0

@ 2vision2下面提到的方法是正確的......但我通過在代碼中詢問兩個權限「publish_stream」和「publish_actions」來解決我的發佈問題,當我只要求其中一個權限時,我無法正常工作,而我不知道爲什麼。 –

回答

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 
} 

所以,如果用戶按下發送和應用程序沒有被授權,它會執行登錄操作並將您的發佈按鈕標題從「登錄」更改爲「發佈」。然後用戶將能夠通過再次按下按鈕來發布消息。

希望它有幫助

相關問題