【问题标题】:GTMOAuth2Authentication with Vimeo使用 Vimeo 进行 GTMOAuth2Authentication
【发布时间】:2014-06-15 16:13:13
【问题描述】:

当我开始学习 OAuth 时还有两天时间,我遇到了下一个问题。我在通过GTMOAuth2Authentication 向 Vimeo 进行身份验证时遇到了一些问题。当我允许对我的应用程序授予权限时,我在 Vimeo 上收到此错误:

“呃哦,出了点问题!发生错误。您将无法连接...”

请检查我的代码并告诉我有什么问题:

- (void)authenticate
{
    GTMOAuth2Authentication * auth = [self configuredAuth];

    // Display the authentication view
    GTMOAuth2ViewControllerTouch * viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth authorizationURL:[NSURL URLWithString:kAuthURL] keychainItemName:kKeychainItemName delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)];

    [_parentView presentViewController:viewController animated:YES completion:nil];
} 

-(GTMOAuth2Authentication *)configuredAuth
{
    NSURL * tokenURL = [NSURL URLWithString:kTokenURL];

    NSString * redirectURI = @"com.mytest.app://";
    GTMOAuth2Authentication * auth;

    auth = [GTMOAuth2Authentication authenticationWithServiceProvider:kKeychainItemName
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:kClientID
                                                     clientSecret:kClientSecret];
    auth.scope = @"public";
    return auth;
}

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

    if (error != nil)
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Vimeo"
                                                         message:[error localizedDescription]
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];

        NSLog(@"%@", error);

        [alert show];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Vimeo"
                                                         message:[error localizedDescription]
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];
        [alert show];
    }

    [viewController dismissViewControllerAnimated:YES completion:nil];
}

我在 Vimeo 的应用程序设置中设置了相同的重定向 URI,当然我在我的应用程序中配置了它(即我能够从 safari 通过com.mytest.app:// 重定向到我的应用程序)。当然,在 kClientID 和 kClientSecret 中定义了来自 developer.vimeo.com 的 ID 和 Secret。

当我关闭 Auth Controller 时,我总是收到这个错误:

Error Domain=com.google.GTMOAuth2 Code=-1000 "操作失败 完成。 (com.google.GTMOAuth2 错误 -1000。)”

这看起来像是重定向(回调)URI 的问题,但我不明白究竟是什么造成了问题。

【问题讨论】:

    标签: ios oauth-2.0 vimeo vimeo-api


    【解决方案1】:

    我认为您的重定向网址不正确。它看起来像一个捆绑 ID。

    NSString * redirectURI = @"com.mytest.app://";   
    

    您是否正确设置了 URL 方案?

    转到 Xcode -> 项目设置 -> 主要目标 -> 信息 -> 网址类型

    确保您的 URL 方案已设置(您已使用 + 按钮添加了 URL 类型),并且您拥有的任何值都与您的重定向 uri 匹配。

    URL Schemes = "testscheme" --> "testscheme://强>”

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      • 2013-01-01
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多