Vimeo与ios oauth 2.0的集成
我们使用oauth 1.0集成了vimeo。现在它不工作了,必须使用OAuth2.0。 我找到了。但我不知道如何将其用于vimeo 我们以前的代码是Vimeo与ios oauth 2.0的集成,ios,oauth-2.0,vimeo,Ios,Oauth 2.0,Vimeo,我们使用oauth 1.0集成了vimeo。现在它不工作了,必须使用OAuth2.0。 我找到了。但我不知道如何将其用于vimeo 我们以前的代码是 OADataFetcher *fetcher; consumer = [[OAConsumer alloc]initWithKey:[dicVimeoInfo objectForKey:@"ConsumerKey"] secret:[dicVimeoInfo objectForKey:@"ConsumerSecret"]]; NS
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。我已经创建了应用程序并找到了“客户端标识符”、“请求令牌URL”、“授权URL”、“访问令牌URL”。现在我不知道该怎么办。在oauth 1.0的早期,我获得了“访问令牌”和“令牌机密”
编辑
我试过这个。我有单用户的访问令牌。vimeo文档说我们发送的标题类似于“curl-H”Authorization:bearer”https://api.vimeo.com
“我该怎么做
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];
编辑
我也尝试过不使用客户端密钥和密码
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对象的一部分提供,但是
客户端凭据
流实际上被定义为使用内容类型设置为application/x-www-form-urlencoded
的普通帖子。因此,Vimeo将无法识别其令牌端点上的有效请求。检查规范中的示例:您使用的URL都是旧API的一部分。所有使用oauth2的请求都通过子域。你可以在上阅读更多内容,你能给我举个例子吗?我试过NSString*str=@“grant\u-type”:“client\u-credentials”,“scope”:“public”}
你的帖子应该是grant\u-type=client\u-credentials&scope=public
而不是像{grant\u-type=client\u-credentials&scope=public>那样的帖子主体;NSData jsonData=[str DATAUSINGENCODE:NSUTF8STRINGENCONDING];[request1 setRequestMethod:@“POST”];[request1 setURL:[NSURL URLWithString:urlPost]];n错误*错误=nil;[request1 setPostBody:(NSMutableData)jsonData];下面是一段经过测试的示例代码:re。您对如何发送令牌的编辑:您不需要在API调用中使用使用者密钥/密码,只需设置Authorization:bearer
头