2

我有一个 iPad 应用程序,需要将 vimeo 集成到它。我正处于将其集成到我的应用程序的初始阶段。我首先需要通过 vimeo 对我的应用程序进行身份验证。

我已经完成了文档中的身份验证步骤,并且能够通过前两个步骤:

请求令牌:http: //vimeo.com/oauth/request_token

用户授权:http: //vimeo.com/oauth/authorize

但无法通过oauth_token最后oauth_token_secret一步:

访问令牌:http: //vimeo.com/oauth/access_token

Vimeo 重定向到回调 url 而不是返回到应用程序,这很好,直到我获得验证程序和授权令牌。但是一旦我使用这些来获取oauth_tokenand oauth_token_secret,控制台就会显示以下错误消息:

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. 
(NSURLErrorDomain error -1012.)" UserInfo=0x18146180 {
    NSErrorFailingURLKey=http://vimeo.com/oauth/access_token?oauth_token=141b4ff56c48dc5d03501297bde85ebc&oauth_verifier=land-1886924229, 
    NSErrorFailingURLStringKey=http://vimeo.com/oauth/access_token?oauth_token=141b4ff56c48dc5d03501297bde85ebc&oauth_verifier=land-1886924229, 
    NSUnderlyingError=0x181483d0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"
}

任何人都可以请帮助或至少提供一些指导吗?

为了进一步深入了解,我正在使用OAuthConsumer框架。以下是我们发出请求以获取访问令牌的代码行:

- (void)successfulAuthorizationWithToken:(NSString *)token verifier:(NSString *)verifier  {
    NSLog(@"successfulAuthorizationWithToken");
    OAMutableURLRequest *request;
    OADataFetcher *fetcher;

    //NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
    NSURL *url = [NSURL URLWithString:@"http://vimeo.com/oauth/access_token"];
    request = [[[OAMutableURLRequest alloc] initWithURL:url
                                               consumer:self.consumer
                                                  token:self.accessToken
                                                  realm:nil
                                      signatureProvider:nil autorelease];


    OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"oauth_token"
                                                                value:token];
    OARequestParameter *p1 = [[OARequestParameter alloc] initWithName:@"oauth_verifier"
                                                                value:verifier];
    NSArray *params = [NSArray arrayWithObjects:p0, p1, nil];
    [request setParameters:params];

    fetcher = [[[OADataFetcher alloc] init] autorelease];

    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
                  didFailSelector:@selector(accessTokenTicket:didFailWithError:)];

    [p0 release];
    [p1 release];

}

我还尝试了以下链接中指定的解决方案: Twitter API + OAuthConsumer.framework

它说使用[[[OAHMAC_SHA1SignatureProvider alloc] init] autorelease]as signatureProvider。但结果是一样的。

使用访问令牌步骤获取验证者和授权令牌后,我需要获取以下值: oauth_token=YourAuthorizedOauthToken&oauth_token_secret=YourAuthorizedTokenSecret

4

2 回答 2

0

终于让它工作了。基本字符串和 oAuth 标头字符串格式存在问题。

于 2011-05-12T11:51:31.307 回答
0

你需要在你的请求中提供你自己的回调,它看起来像在 iOS 中myapp://...注册myapp处理程序,这样当浏览器被重定向时,iOS 会将控制权交还给你的应用程序。我假设您正确使用 OAuth 并从您的应用程序启动浏览器以进行用户交互。或者,您可以使用 WebView(不是 OAuth 推荐的),然后在 WebView 委托中,您可以捕获重定向并解析access toke

于 2011-05-12T06:33:11.673 回答