2

我試圖訪問Twitter的API的單個部分應用程序的憑據,而無需在用戶帳戶登錄(應用程序唯一的身份驗證是我想要的),所以我不想添加一些框架來執行這一操作。我試圖用AFNetworking來做,而不是基於這裏的描述:https://dev.twitter.com/oauth/reference/post/oauth2/token如何使用AFOAuth2Manager以獲取Twitter的REST API

這裏是我到目前爲止

AFOAuth2Manager *authManager = [[AFOAuth2Manager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/"] 
                   clientID:TwitterAPIKey 
                   secret:TwitterSecret]; 
[authManager authenticateUsingOAuthWithURLString:@"oauth2/token" 
             parameters:nil 
             success:^(AFOAuthCredential *credential) { 
              AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:TwitterBaseURL]]; 
              [manager.requestSerializer setAuthorizationHeaderFieldWithCredential:credential]; 
              //do some stuff 
             } 
             failure:^(NSError *error) { 
              //handle the failure, where I'm currently ending up 
             }]; 

運行時,這種失敗與403 Forbidden錯誤進行身份驗證。任何人都可以向我解釋我要出錯的地方嗎?

回答

4

這是一個愚蠢的錯誤 - 我不知道,我需要的參數。通過@{@"grant_type": @"client_credentials"}獲取參數而不是nil修復了此問題。

+0

謝謝你發佈你的答案。這是什麼讓偉大。 –

相關問題