我正在使用vimeo advance api来搜索视频,例如在youtube和日常动作中查询 . vimeo advance api需要oauth身份验证 . 我希望vimeo像vimeo游乐场一样让我回归json . https://developer.vimeo.com/apis/advanced/methods/vimeo.videos.search/playground . 我写下面的代码来获取json数据,但不知道我是谁获得了json数据
- (void)viewDidLoad
{
[super viewDidLoad];
SBJsonParser *json = [[SBJsonParser alloc]init];
// Do any additional setup after loading the view, typically from a nib.
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"0c5e6dd9b8fa5f8d91563332da03912ac8c2e15d"
secret:@"744eb15d911ee3607f7006f1f4ad7eb17a94eec6"];
NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/request_token"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:nil
realm:nil
signatureProvider:nil];
[request setParameters: [NSArray arrayWithObjects: [[OARequestParameter alloc] initWithName: @"oauth_callback" value: @"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.search&qdfduery=amir+khan"] ,nil]];
[request setHTTPMethod:@"GET"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)
didFailSelector:nil];
}
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
if (ticket.didSucceed)
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
OAToken *requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
NSLog(@"data %@",requestToken);
OAMutableURLRequest *request;
if (self.accessToken != nil) {
self.accessToken = nil;
}
self.accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
NSLog(@"access token key %@",self.accessToken.key) ;
NSLog(@"access token secret %@",self.accessToken.secret) ;
NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/authorize"];
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:self.accessToken.key
secret:self.accessToken.secret];
request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:self.accessToken
realm:nil
signatureProvider:nil];
OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"oauth_token" value:self.accessToken.key];
NSArray *params = [NSArray arrayWithObject:p0];
[request setParameters:params];
[webView loadRequest:request];
NSLog(@"request %@",request);
}
}
上面的代码返回我的访问令牌 . 但我不知道如何使用该访问令牌来获取像vimeo游乐场中的json . 亲切的任何人为我完成它我很困惑因为在vimeo网站上他们没有正确的指导我如何使用advance api
1 回答
获得访问令牌后,您需要针对“http://vimeo.com/api/rest/v2” endpoints 发出经过身份验证的请求 .
此请求必须遵循您在检索oauth令牌时执行的相同oauth 1.0a签名过程 .
您还必须通过querystring参数提供api方法,因此要搜索视频,您需要提供method = vimeo.videos.search . 您可以在“请求” Headers 下的操场上看到此示例 .
任何其他参数(例如format = json)也通过查询字符串处理 .