0

我想知道是否有人知道在swift3中更新的代碼以下。我從Parse Server github得到了這個(下面的鏈接)。解析Facebook登錄集成處理失效會話

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]; 
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
if (!error) { 
    // handle successful response 
} else if ([[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]) { // Since the request failed, we can check if it was due to an invalid session 
    NSLog(@"The facebook session was invalidated"); 
    [PFFacebookUtils unlinkUserInBackground:[PFUser currentUser]]; 
} else { 
    NSLog(@"Some other error: %@", error); 
} 

}];

具體來說,我想明白了什麼,以檢查

"[[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]". 

我明白,如果swift3我想設置爲

"if error = (error as? NSError!).userInfo[something]" 

但我不知道我需要哪個參數在userinfo []中傳遞。例如。 FBSDKGraphRequestErrorCategoryKey,FBSDKGraphRequestErrorGraphError等

https://github.com/ParsePlatform/ParseUI-iOS/wiki/Integrate-Login-with-Facebook

+0

對不起,我想知道你在哪裏問! – Cliffordwh

+0

@Cliffordwh沒問題! – DevKyle

回答

0

API將在JSON體說明錯誤的性質返回HTTP 400狀態代碼,代碼和一個子碼。在你的情況下,無效的會議。只需將其轉換爲變量並檢查它是否等於"OAuthException"

{ 
     "error": { 
     "message": "Error validating access token: The session is invalid 
        because the user logged out.", 
     "type": "OAuthException", 
     "code": 190 
     } 
    } 
+0

我在Facebook開發者網站上也看到了這一點。我將如何使它適合swift中的「error.userInfo」格式? – DevKyle