場景:通過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