2

我在获取 vimeo 高级搜索 api 时收到 json 格式的此错误,这是错误

{"code":"401","expl":"The oauth_token passed has not been authorized by the user.","msg":"Invalid token"}}

这是我在 vimeo 上的身份验证代码。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    consumer = [[OAConsumer alloc] initWithKey:@"xxxxxxxxxxxx"
                                                    secret:@"xxxxxxxxxxxx"];

    NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/request_token"];

    OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                                                   consumer:consumer
                                                                      token:nil   // we don't have a Token yet
                                                                      realm:nil   // our service provider doesn't specify a realm
                                                          signatureProvider:nil]; // use the default method, HMAC-SHA1

    [request setParameters: [NSArray arrayWithObjects: [[OARequestParameter alloc] initWithName: @"oauth_callback" value: @"http://iosdevelopertips.com/networking/iphone-json-flickr-tutorial-part-1.html"] ,nil]];

    [request setHTTPMethod:@"GET"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];

    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)
                  didFailSelector:@selector(requestTokenTicket:didFailWithError:)];

}

- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
    NSLog(@"ticket value %@",ticket);
    if (ticket.didSucceed) {
        NSString *responseBody = [[NSString alloc] initWithData:data
                                                       encoding:NSUTF8StringEncoding];
        requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
    }
    NSString *urlString = [NSString stringWithFormat:@"https://vimeo.com/oauth/authorize?auth_token=%@", requestToken.key];
    NSURL *urlAuth = [NSURL URLWithString:urlString];
    [[UIApplication sharedApplication] openURL:urlAuth];

    NSURL *url = [NSURL URLWithString:@"http://vimeo.com/api/rest/v2?method=vimeo.videos.search"];
    OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                                                   consumer:consumer
                                                                      token:requestToken
                                                                      realm:nil
                                                          signatureProvider:[[OAHMAC_SHA1SignatureProvider alloc] init]];

    OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:@"format"
                                                                       value:@"json"];
    OARequestParameter *descParam = [[OARequestParameter alloc] initWithName:@"query"
                                                                       value:@"amir khan"];
    NSArray *params = [NSArray arrayWithObjects:nameParam, descParam, nil];
    [request setParameters:params];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(requestTokenTicket2:didFinishWithData:)
                  didFailSelector:@selector(requestTokenTicket2:didFinishWithData:)];
}

- (void)requestTokenTicket2:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data
{
    NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"data string %@",dataString);
}
4

1 回答 1

0

错误消息“传递的 oauth_token 未经用户授权”表示您使用的是请求令牌,而不是访问令牌。

请求令牌是您在用户通过您的应用程序进行身份验证之前获得的令牌。此令牌用于构建您将用户发送到的 url。

一旦用户在 vimeo.com 上批准了您的应用程序,他们将被重定向到您的应用程序。此时,您应该将您的请求令牌交换为访问令牌。

于 2013-07-24T20:49:47.600 回答