问题
We had vimeo integrated using oauth 1.0. Now its not working and have to use oauth 2.0. I found https://github.com/nxtbgthng/OAuth2Client. But do not understand how to use it for vimeo.
Our earlier code was
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:)];
Now Vimeo has shifted to oauth 2.0. I have created app and found "Client Identifier", "Request Token URL", "Authorize URL", "Access Token URL". Now I am not sure How to go about. Earlier in oauth 1.0 I was getting "Access Token" and "Token Secret".
Edit
I tried this. I have access token for single user. vimeo documents says we send header like "curl -H "Authorization: bearer <OAUTH_TOKEN>" https://api.vimeo.com
" How can i do it.
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];
Edit I tried without client key and secret also.
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);
output is same
Response : {
err = {
code = 401;
expl = "The consumer key passed was not valid.";
msg = "Invalid consumer key";
};
"generated_in" = "0.0020";
stat = fail;
}
Thanks.
回答1:
You're supplying the parameters as part of a JSON object but the client_credentials
flow is actually defined as using a plain POST with Content-Type
set to application/x-www-form-urlencoded
. Hence Vimeo won't recognize a valid request at its token endpoint. Check the example in the spec at: http://tools.ietf.org/html/rfc6749#section-4.4.2
回答2:
The URL's you are using are all part of the old API. All requests using oauth2 go through the https://api.vimeo.com subdomain. You can read more at https://developer.vimeo.com/api/authentication
来源:https://stackoverflow.com/questions/27523860/vimeo-integration-to-ios-oauth-2-0