我在获取 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);
}