当我开始学习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://
重定向到我的应用)。当然还有来自developer.vimeo.com的kClientID
和kClientSecret
定义的ID和秘密。
当我关闭Auth Controller时,我总是收到此错误:
错误Domain = com.google.GTMOAuth2 Code = -1000"操作无法执行 完成。 (com.google.GTMOAuth2错误-1000。)"
它看起来像重定向(回调)URI的问题,但我无法理解究竟是什么问题。
答案 0 :(得分:0)
我认为您的重定向网址不正确。它看起来像一个包ID。
NSString * redirectURI = @"com.mytest.app://";
您是否正确设置了URL方案?
转到 Xcode - > 项目设置 - > 主要目标 - > 信息 - > 网址类型
确保您的网址架构已设置(您已添加带有+按钮的网址类型),并且您拥有的任何值都与您的重定向uri相匹配。
网址结构 =“ testscheme ” - > “的 testscheme:// 强>”
祝你好运!