我们使用 oauth 1.0 集成了 vimeo。现在它不起作用,必须使用 oauth 2.0。 我找到了 https://github.com/nxtbgthng/OAuth2Client 。但不明白如何将其用于vimeo。
我们之前的代码是
OADataFetcher *fetcher;
consumer = [[OAConsumer alloc]initWithKey:[dicVimeoInfo objectForKey:@"ConsumerKey"] secret:[dicVimeoInfo objectForKey:@"ConsumerSecret"]];
NSURL *vimeoURL=[NSURL URLWithString:kVimeoRestURL];
OAToken *token=[[OAToken alloc]initWithKey:[dicVimeoInfo objectForKey:@"AccessToken"] secret:[dicVimeoInfo objectForKey:@"AccessTokenSecret"]];
request = [[OAMutableURLRequest alloc] initWithURL:vimeoURL
consumer:consumer
token:token
realm:nil
signatureProvider:nil];
OARequestParameter* formatparameter = [OARequestParameter requestParameter:@"format" value:@"json"];
OARequestParameter* methodParameter = [OARequestParameter requestParameter:@"method" value:@"vimeo.channels.getAll"];
NSArray *params = [NSArray arrayWithObjects: formatparameter, methodParameter, nil];
[request setParameters:params];
[request setHTTPMethod:@"GET"];
[request prepare];
fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)
didFailSelector:@selector(requestTokenTicket:didFailWithError:)];
现在 Vimeo 已转向 oauth 2.0。我创建了应用程序并找到“客户端标识符”、“请求 token URL”、“授权 URL”、“访问 token URL”。现在我不知道该怎么办。在 oauth 1.0 的早期,我获得了“访问 token ”和“ token secret ”。
编辑
我试过这个。我有单个用户的访问 token 。 vimeo 文档说我们发送像“curl -H "Authorization: bearer <OAUTH_TOKEN>" https://api.vimeo.com
”这样的 header ,我该怎么做。
consumer = [[OAConsumer alloc]initWithKey:@"456a8852ebd72760de4d2206bab3dad0db35a66b" secret:@"eb74abb5d1f38ad0bd570d24e4d1d0ee3a447534"];
NSURL *url = [NSURL URLWithString:@"http://vimeo.com/api/rest/v2"];
request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:nil
realm:nil
signatureProvider:nil];
[request setParameters: [NSArray arrayWithObjects: [OARequestParameter requestParameter:@"method" value:@"vimeo.channels.getAll"],[OARequestParameter requestParameter:@"format" value:@"json"], nil]];
[request addValue:[NSString stringWithFormat:@"bearer %@",@"a75a63c0e0121b0704a4c98d6e209eb2"] forHTTPHeaderField:@"Authorization"];
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)
didFailSelector:nil];
编辑 我也尝试过没有客户端 key 和 secret 。
NSURL *aUrl = [NSURL URLWithString: @"http://vimeo.com/api/rest/v2?format=json&method=vimeo.channels.getAll"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
[request addValue:[NSString stringWithFormat:@"bearer %@",@"7c7139ec99fa9e09f77dd2512780c301"] forHTTPHeaderField:@"Authorization"];
[request setHTTPMethod:@"GET"];
NSError *error = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error: &error];
NSDictionary *JSONDictionary = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error];
NSLog(@"Response : %@", JSONDictionary);
输出相同
Response : {
err = {
code = 401;
expl = "The consumer key passed was not valid.";
msg = "Invalid consumer key";
};
"generated_in" = "0.0020";
stat = fail;
}
谢谢。
最佳答案
您将参数作为 JSON 对象的一部分提供,但 client_credentials
流程实际上定义为使用普通 POST,并将 Content-Type
设置为 应用程序/x-www-form-urlencoded
。因此,Vimeo 将无法识别其 token 端点处的有效请求。检查规范中的示例:https://www.rfc-editor.org/rfc/rfc6749#section-4.4.2
关于ios - Vimeo 集成到 ios oauth 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27523860/