当我开始学习 OAuth 时还有两天时间,我遇到了下一个问题。我在通过GTMOAuth2Authentication
. 当我允许对我的应用程序授予权限时,我在 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.comkClientID
中kClientSecret
定义了 ID 和 Secret。
当我关闭 Auth Controller 时,我总是收到此错误:
错误 Domain=com.google.GTMOAuth2 代码=-1000 “操作无法完成。(com.google.GTMOAuth2 错误 -1000。)”
这看起来像是重定向(回调)URI 的问题,但我不明白究竟是什么造成了问题。