【问题标题】:How do I use AFOAuth2Manager to get application credentials for the Twitter REST API如何使用 AFOAuth2Manager 获取 Twitter REST API 的应用程序凭据
【发布时间】:2015-07-14 10:12:09
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c afnetworking twitter-oauth twitter-rest-api


    【解决方案1】:

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

    【讨论】:

    • 感谢您发布您的答案。这就是如此伟大的原因。
    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 2020-10-20
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2019-03-29
    • 2014-12-05
    • 2012-06-04
    相关资源
    最近更新 更多