【问题标题】:Yahoo OAuth Error 401 Consumer Key Unknown雅虎 OAuth 错误 401 消费者密钥未知
【发布时间】:2014-08-07 02:59:37
【问题描述】:

我正在尝试通过向以下 URL 发出 POST 请求来从 Yahoo 获取请求令牌: https://api.login.yahoo.com/oauth/v2/get_request_token

我通过以下方式提出请求:

int randomNumber = rand();

NSDictionary *parameters = @{@"oauth_consumer_key": YahooConsumerKey,
                             @"oauth_signature_method": @"plaintext",
                             @"oauth_signature": YahooConsumerSecret,
                             @"oauth_version": @"1.0",
                             @"xoauth_lang_pref": @"en_us",
                             @"oauth_callback": @"oob",
                             @"oauth_timestamp": [self getTimeStamp],
                             @"oauth_nonce": [NSString stringWithFormat:@"%d", randomNumber]};

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager POST:@"https://api.login.yahoo.com/oauth/v2/get_request_token" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

问题是我不断收到错误 401,并解释说使用者密钥未知。我已经粘贴了我创建项目的地方的消费者密钥,所以我真的不知道我做错了什么。任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 您是否尝试过手动创建带有 GET 参数的请求 URL 并将其粘贴到浏览器中?我目前正在使用 Yahoo OAuth 1.0a,它对我来说运行良好。你能在 GET 中打印出完整的请求,看看它是什么样子的吗?
  • 是的,请求看起来像这样link@michaelchum
  • 试试我的答案中的链接,您只需将%26 附加到您的消费者密码中。我还在为 Yahoo OAuth 1.0a 开发改进的 iOS SDK,应该很快就会发布!
  • 如果这对你有用,请告诉我!
  • @michaelchum 请求有效,但是当我尝试使用 AFNetworking 发出请求时,它会在字符串末尾添加 %2526,因此请求将不起作用。我正在尝试使用 NSMutableURLRequest 以经典方式提出请求。

标签: ios objective-c oauth request yahoo


【解决方案1】:

您的请求看起来不错。尝试将 @"%26" 附加到您的 YahooConsumerSecret 字符串中。这是您的请求 link 修复,它似乎正在工作!

根据 Yahoo 文档,当使用 plaintext 作为 oauth_signature_method 时,您需要在 oauth_signature 的末尾附加 %26

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 2012-07-29
    • 2012-09-28
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多