【问题标题】:Authentication needed error with ASIHTTPRequestASIHTTPRequest 需要身份验证错误
【发布时间】:2012-12-12 12:26:15
【问题描述】:

我做了很多谷歌搜索,但我找不到任何可以理解的 ASIHttpRequest 和 Youtube API 教程。我还在 Stackoverflow 和其他论坛上问了很多问题,但没有人能提供帮助。 我尝试从 youtube 获取最喜欢的视频列表。我已成功登录并获得了访问令牌。我将其设置为带有密钥授权的请求标头,但 Youtube 总是返回错误:

响应失败并显示消息:错误域=ASIHTTPRequestErrorDomain 代码=3“需要验证”用户信息=0x933b980 {NSLocalizedDescription=需要验证}

这是我的代码:

#define CONNECTION_GET_FAVORITE_LIST @"https://gdata.youtube.com/feeds/api/users/default/favorites"

- (void) getFavoriteList{


  NSURL *url = [NSURL URLWithString:CONNECTION_GET_FAVORITE_LIST];
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    [request addRequestHeader:@"Authorization" value:[@" Bearer "  stringByAppendingString:<accesstoken goes here>];
    request 
    [request startAsynchronous];
    [request setCompletionBlock:^{
        NSString* respondMessage = [request responseString];
        NSLog(@"Respond complete with message: %@",respondMessage);
    }];
    [request setFailedBlock:^{
        NSString* respondMessage = [request error];
        NSLog(@"Respond failed with message: %@",respondMessage);
    }];
    [request release];
}

更新:当我尝试使用方法 GET 并将链接上的访问令牌设置为:https://gdata.youtube.com/feeds/api/users/default/favorites?v=2&amp;access_token=&lt;accesstoken&gt;,youtube 抛出错误:

令牌无效 - AuthSub 令牌范围错误

错误 401

请帮我解决这个问题。 非常感谢

【问题讨论】:

标签: objective-c ios youtube-api asihttprequest gdata-api


【解决方案1】:

首先不要使用ASIHTTPRequest 使用AFNetworking。但在这里你不需要任何人。

现在您的请求需要authentication and authorizationgdata 以请求在youtube 中获取feed

编辑:参考gtm-oauth2链接。

参考GData Youtube API Documenttaion链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    相关资源
    最近更新 更多