Sto cercando di ottenere un codice di autenticazione di Google+ in base a questo articolo: Server-side access for your app. Tuttavia, ogni volta che corro la mia app e cercare di ottenere il codice ottengo il seguente in LogCat:Android Google+ non è in grado di ottenere il codice di autenticazione
07-23 23:42:31.760: E/getAccessToken()(11114): [ERROR] GoogleAuthException: com.google.android.gms.auth.GoogleAuthException: Unknown
ho passato in rassegna un sacco di roba e da quello che posso dire Ho installato tutto correttamente nel seguente codice. Qualche idea sul perché non ottiene un token di autenticazione?
FYI, ho una configurazione di progetto nella console API che ha sia l'app che le applicazioni web configurate per oauth e sto usando l'ID del server (non l'app) per la stringa degli ambiti. Ho seguito anche gli esempi dal link precedente e l'app funziona correttamente e ti consente di accedere/uscire, ma non riesco a ottenere il codice di autenticazione.
private String getAccessToken() {
String scopesString = Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE;
String scope = "oauth2:server:client_id:" + SERVER_CLIENT_ID + ":api_scope:" + scopesString;
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
"http://schemas.google.com/AddActivity");
String code = null;
try {
code = GoogleAuthUtil.getToken(
this, // Context context
mPlusClient.getAccountName(), // String accountName
scopes, // String scope
appActivities // Bundle bundle
);
} catch (IOException transientEx) {
// network or server error, the call is expected to succeed if you try again later.
// Don't attempt to call again immediately - the request is likely to
// fail, you'll hit quotas or back-off.
Log.e("getAccessToken()", "[ERROR] IOException: " + transientEx);
return null;
} catch (UserRecoverableAuthException e) {
// Recover
Log.e("getAccessToken()", "[ERROR] UserRecoverableAuthException: " + e);
code = null;
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should not be
// retried.
Log.e("getAccessToken()", "[ERROR] GoogleAuthException: " + authEx);
return null;
} catch (Exception e) {
Log.e("getAccessToken()", "[ERROR] Exception: " + e);
throw new RuntimeException(e);
}
return code;
}
Scusa, mia cattiva. Sembra che ho rimosso quella parte quando l'ho pubblicata, ho ": api_scope:" nel mio codice. Ho aggiornato il post per dimostrarlo. – Jason
Ahhh ... Mi è mancato separare scopeString alla fine. Ho apportato questa modifica e ora ricevo un errore "UserRecoverableAuthException: NeedPermission". Ho provato a gestirlo, ma ora sto fondamentalmente avendo [questo problema] (http://stackoverflow.com/questions/17713435/android-google-integration-repeated-userrecoverableauthexception). Lo contrassegnerò come corretto, dal momento che ha risolto il problema iniziale che stavo facendo ... stupido errore a tarda notte ;-) – Jason
Da quando il metodo GoogleAuthUtil.getToken() ha iniziato a lanciare un'eccezione GoogleAuthException con messaggio "BadUsername" per un'email che non è registrato su un dispositivo, invece dell'eccezione precedente IllegalArgumentException con messaggio "Account non esistente 'indirizzo_email'"? http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context, java.lang.String, java.lang.String) – toobsco42