Android Drive API OAuth BAD_AUTHENTICATION

I have a problem with the REST v3 API for Google Drive. The OAuth current gets the result of BAD_AUTHENTICATION. Here is the connection code I'm using. It can also be noted that the OAuth consent screen is not displayed, and after a short period of time I get the result BAD_AUTHENTICATION. Should I manually transfer the update token to the server or something else?

// Gather credentials
credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES)).setBackOff(new ExponentialBackOff());
SharedPreferences settings = getSharedPreferences("Roblu", Context.MODE_PRIVATE);
String accountName = settings.getString("accountName", "");
credential.setSelectedAccountName(accountName);

// Start Google services
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
service = new com.google.api.services.drive.Drive.Builder(transport, jsonFactory, credential).setApplicationName("Roblu").build();

Here is the result code:

08-15 14:11:27.621 4929-15182/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:-238957088>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/games
                                    dkq: Long live credential not available.
                                        at dkr.a(:com.google.android.gms:3101)
                                        at dje.a(:com.google.android.gms:397)
                                        at djd.a(:com.google.android.gms:31369)
                                        at djd.a(:com.google.android.gms:313)
                                        at elb.a(:com.google.android.gms:1201)
                                        at ela.a(:com.google.android.gms:530)
                                        at ela.a(:com.google.android.gms:196)
                                        at dfw.a(:com.google.android.gms:320)
                                        at dfw.a(:com.google.android.gms:210)
                                        at dgf.a(:com.google.android.gms:1498)
                                        at dge.a(:com.google.android.gms:909)
                                        at dge.e(:com.google.android.gms:523)
                                        at dgd.a(:com.google.android.gms:37)
                                        at dhm.getAuthToken(:com.google.android.gms:178)
                                        at android.accounts.AbstractAccountAuthenticator$Transport.getAuthToken(AbstractAccountAuthenticator.java:214)
                                        at android.accounts.IAccountAuthenticator$Stub.onTransact(IAccountAuthenticator.java:113)
                                        at android.os.Binder.execTransact(Binder.java:453)
+4
source share
1 answer

thread, , , , , Google, , , . . Google API- API Google Java.

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   ...
   // Google Accounts using OAuth2
   m_credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(DriveScopes.DRIVE));

   m_client = new com.google.api.services.drive.Drive.Builder(
            m_transport, m_jsonFactory, m_credential).setApplicationName("AppName/1.0")
            .build();
   ...
}

:

, !

+2

Source: https://habr.com/ru/post/1651324/


All Articles