Vimeo身份验证OAuth2

时间:2015-03-19 14:18:42

标签: ios objective-c authentication oauth vimeo

我正在尝试通过iOS应用程序与Vimeo进行身份验证。我正在使用GTMOAuth2Authentication Oauth2库。我的代码如下:

- (void)signInToVimeo
{
    GTMOAuth2Authentication * auth = [self authForVimeo];

    GTMOAuth2ViewControllerTouch * viewController = 
    [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth

    authorizationURL:[NSURL URLWithString:@""]

    keychainItemName:@"VimeoKeychainItem"
                                                                                 delegate:self

    finishedSelector:@selector(viewController:

    finishedWithAuth:error:)];

    [self.navigationController pushViewController:viewController animated:YES];
}

- (GTMOAuth2Authentication * )authForVimeo
{
    NSURL * tokenURL = [NSURL URLWithString:VIMEO_REQUEST_TOKEN_URL];

    NSString * redirectURI = @"vimeoTest://";

    GTMOAuth2Authentication * auth;

    auth = [GTMOAuth2Authentication   

    authenticationWithServiceProvider:@"Vimeo"

    tokenURL:tokenURL

    redirectURI:redirectURI

    clientID:CLIENT_ID                                   

    clientSecret:SECRET_KEY];
    auth.scope = @"edit";
    return auth;
}

- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController
      finishedWithAuth:(GTMOAuth2Authentication * )auth
                 error:(NSError * )error
{
    NSLog(@"auth access token: %@", auth.accessToken);
    NSLog(@"%@", [error localizedDescription]);
}

我在应用程序和Vimeo开发者网站的URL方案中设置了相同的回调网址vimeoTest://。 Vimeo登录界面显示效果良好,输入登录凭据后请求“允许”或“取消”;这很好但是当我点击“允许”时,我没有收到错误消息“com.google.HTTPStatus error 404”的设备令牌。是否有任何Vimeo身份验证和上传示例?

1 个答案:

答案 0 :(得分:0)

当我将回调网址更改为自己的回复网址时,我遇到了同样的错误。这是因为如果您正在使用VIMNetworking,则回调URL必须采用vimeoCLIENT_ID格式。为什么?如果您查看VIMNetworking来源,您会注意到

- (id<VIMRequestToken>)authenticateWithCodeGrantResponseURL:(NSURL *)responseURL completionBlock:(VIMAccountCompletionBlock)completionBlock

使用

- (NSString *)codeGrantRedirectURI
{
   NSString *authRedirectScheme = [NSString stringWithFormat:@"vimeo%@", self.clientKey];
   NSString *authRedirectPath = @"auth";
   return [NSString stringWithFormat:@"%@://%@", authRedirectScheme, authRedirectPath];
} 

查看authRedirectScheme字符串;)