2

我正在尝试访问 Twitter API 的单个部分,而无需登录用户帐户(我想要的是仅应用程序身份验证),因此我不想添加一些框架来执行这一操作。我正在尝试根据此处的描述使用 AFNetworking 来做到这一点:https ://dev.twitter.com/oauth/reference/post/oauth2/token 。

这是我到目前为止所拥有的

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 禁止错误进行身份验证。谁能向我解释我哪里出错了?

4

1 回答 1

4

这是一个愚蠢的错误——我没有意识到我需要一个参数。传递@{@"grant_type": @"client_credentials"}参数而不是nil解决此问题。

于 2015-05-04T22:28:46.100 回答