Scenario: login per App tramite Google+ AccessoGoogle Plus Accesso
Implementazione:
- (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);
}
}
Nota: - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation
viene gestito nel AppDelegate.
Problema:
- Il login Google+ funziona perfettamente bene quando l'utente fa clic sul pulsante Google SignIn ed è navigato al Safari. Un AccessToken valido viene ricevuto nella mia app.
- Tuttavia, se l'app Google+ è disponibile su iPhone, l'utente viene spostato nell'app Google+ ma su Accedi non viene ricevuto AccessToken. Ottengo un errore.
Errore:
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)
Sarà molto utile se qualcuno mi può guidare nella soluzione di questo problema. Grazie.
Hai messo la tua app s ID bundle su Google Developer Console? Questo è l'unico modo per avviare l'app da WebView o Safari nell'API di Google+. – khunshan
Sì. Sì, ma l'errore rimane lo stesso. – Nishi
@Nishi Hai qualche soluzione? Sto affrontando lo stesso numero http://stackoverflow.com/questions/30160104/authentication-not-working-with-google-app – Tariq