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錯誤進行身份驗證。任何人都可以向我解釋我要出錯的地方嗎?
謝謝你發佈你的答案。這是什麼讓偉大。 –