场景:通过Google+登录谷歌加登录
实现登录到App:
- (void)viewDidLoad {
[super viewDidLoad];
GPPSignIn *aGPSSignIn = [GPPSignIn sharedInstance];
aGPSSignIn.scopes = @[ kGTLAuthScopePlusLogin, kGTLAuthScopePlusUserinfoEmail, kGTLAuthScopePlusUserinfoProfile, kGTLAuthScopePlusMe];
aGPSSignIn.shouldFetchGoogleUserEmail = YES;
aGPSSignIn.shouldFetchGooglePlusUser =YES;
aGPSSignIn.homeServerClientID = kClientID;
aGPSSignIn.clientID = kClientID;
aGPSSignIn.delegate = self;
if (![aGPSSignIn trySilentAuthentication]) {
[self showLoginButton];
}
}
- (void)showLoginButton {
if (!self.signInButton) {
self.signInButton = [GPPSignInButton buttonWithType:UIButtonTypeCustom];
[self.signInButton setFrame:CGRectMake(60, 100, 200, 40)];
}
[self.view addSubview:self.signInButton];
}
#pragma mark - GPPSignInDelegate
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error {
NSString *anAccessToken = auth.accessToken;
NSLog(@"googleAccessToken:%@",anAccessToken);
}
- (void)didDisconnectWithError:(NSError *)iError {
if (iError) {
NSLog(@"Error:%@", iError);
}
}
注:- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation
,在AppDelegate处理。
问题:
- 当用户点击谷歌登入按钮,并导航到Safari浏览器的Google+帐户登录工作完全正常。我的应用程序接收到有效的AccessToken。
- 但是,如果Google+应用程序在iPhone上可用,用户将被导航到Google+应用程序,但在登录时不会收到AccessToken。我收到一个错误。
错误:
Received error Error Domain=com.google.GooglePlusPlatform Code=-1 "The operation couldn’t be completed. (com.google.HTTPStatus error 400.)" UserInfo=0x15d95f90 {NSLocalizedDescription=The operation couldn’t be completed. (com.google.HTTPStatus error 400.)} and auth object (null)
这将是非常有益的,如果有人能指导我解决这个问题。 谢谢。
你把你的应用程序Google开发者控制台上的套件ID?这是WebView或Safari API在Google+ API中启动应用程序的唯一途径。 – khunshan 2014-11-25 19:22:03
是的,我做了。但仍然错误保持不变。 – Nishi 2014-11-26 10:48:40
@Nishi你有什么解决方案吗?我面临同样的问题http://stackoverflow.com/questions/30160104/authentication-not-working-with-google-app – Tariq 2015-05-15 08:39:42