Iphone 谷歌OAuth错误-1001
在我的应用程序中,我尝试实现google帐户访问,并在登录会话中初始化它。之后,它在屏幕截图中抛出以下错误 这是我的密码 初始化和方法实施Iphone 谷歌OAuth错误-1001,iphone,ios,google-oauth,Iphone,Ios,Google Oauth,在我的应用程序中,我尝试实现google帐户访问,并在登录会话中初始化它。之后,它在屏幕截图中抛出以下错误 这是我的密码 初始化和方法实施 static NSString *const kKeychainItemName =nil; NSString *kMyClientID = @"465568347336.apps.googleusercontent.com"; NSString *kMyClientSecret = @"rKVsWXTlo3M8zqNfofkX0Xrl";
static NSString *const kKeychainItemName =nil;
NSString *kMyClientID = @"465568347336.apps.googleusercontent.com";
NSString *kMyClientSecret = @"rKVsWXTlo3M8zqNfofkX0Xrl";
NSString *scope = @"https://www.googleapis.com/auth/userinfo.profile";
GTMOAuth2ViewControllerTouch *viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
clientID:kMyClientID
clientSecret:kMyClientSecret
keychainItemName:kKeychainItemName
delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController presentModalViewController:viewController animated:YES];
错误处理程序
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error != nil) {
NSString *output=nil;
output = [error description];
NSLog(@"output:%@",output);
UIAlertView *fail = [[UIAlertView alloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Error, Authentication failed!\n %@",error]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Try again", nil];
fail.tag = 1;
[fail show];
NSLog(@"Authentication failed!");
} else {
UIAlertView *success = [[UIAlertView alloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Authentication succeeded!"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
success.tag = 2;
[success show];
NSLog(@"Autzentication succeeded!");
}
如何解决这个问题。请帮助我解决这个问题。我使用以下代码实现了我的GTMOAuth2,它对我很有效,我希望它能以某种方式帮助您
- (GTMOAuth2Authentication * )authForGoogle
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
_auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"Google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
_auth.scope = @"https://www.googleapis.com/auth/userinfo.profile";
return _auth;
}
- (void)signInToGoogle
{
_auth = [self authForGoogle];
// Display the authentication view
GTMOAuth2ViewControllerTouch * viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:_auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:@"GoogleKeychainName"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[_window setRootViewController: viewController];
[_window makeKeyAndVisible];
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error
{
if (error != nil) {
NSString *output=nil;
output = [error description];
NSLog(@"output:%@",output);
UIAlertView *fail = [[UIAlertView alloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Error, Authentication failed!\n %@",error]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Try again", nil];
fail.tag = 1;
[fail show];
NSLog(@"Authentication failed!");
} else {
UIAlertView *success = [[UIAlertView alloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Authentication succeeded!"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
success.tag = 2;
[success show];
NSLog(@"Autzentication succeeded!");
}
}
我复制了finishedWithAuth方法,因为它与我的实现类似。在xcode中实现GTMOAuth2方面,我认为我们的代码之间没有太大区别,但我在使用GTMOAuth2时意识到,调试您所面临的任何错误都非常困难。我也遇到过类似的错误,并且意识到这是因为我在设置应用程序并获取clientID和clientSecret时在Google portal中选择了错误的应用程序类型。起初我将它设置为一个iOS应用程序(当然!),但在网上阅读了不同的答案和问题后,我意识到我应该将它创建为另一种应用程序类型。这解决了我的问题。也许你可以看看
他们有一个支持相当全面的论坛,这是链接
为了进一步补充,我可以让您参考我在将GTMOAuth2集成到我的应用程序时参考的教程。这是链接
此外,由于我正在开发一个企业应用程序,要求我检查用户的电子邮件地址,因此即使在用户经过身份验证后,我也很难获得电子邮件。在我得到我需要的东西之前,我必须破解并阅读代码,如果你将来需要它,你可以检查我的答案
希望这有帮助!:)
Error Domain=com.google.GTMOAuth2 code=-1001
通常在用户登录时发生,但在OAuth协议窗口中(其中显示“想要访问您的电子邮件”,例如),用户单击“取消”或“不感谢”
所以基本上没有办法“解决”这个问题。你可以处理它,也可以在没有这些服务的情况下在你的应用程序中继续前进