Android Drive API OAuth BAD_AUTHENTICATION [英] Android Drive API OAuth BAD_AUTHENTICATION
问题描述
我遇到Google Drive REST v3 android API的问题。 OAuth令牌获得BAD_AUTHENTICATION结果。这是我正在使用的连接代码。还可以注意到,OAuth许可屏幕没有显示出来,经过一段时间后,我得到了BAD_AUTHENTICATION结果。我需要手动将刷新令牌传递给服务器或其他东西?
//收集凭证
凭证= GoogleAccountCredential使用OAuth2(getApplicationContext(),Arrays.asList(SCOPES))。setBackOff(new ExponentialBackOff());
SharedPreferences设置= getSharedPreferences(Roblu,Context.MODE_PRIVATE);
String accountName = settings.getString(accountName,);
credential.setSelectedAccountName(accountName);
//启动Google服务
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
service = new com.google.api.services.drive.Drive.Builder(transport,jsonFactory,credential).setApplicationName(Roblu)。build();
以下是结果代码:
08-15 14:11:27.621 4929-15182 /? E / Auth:[GoogleAccountDataServiceImpl] getToken() - > BAD_AUTHENTICATION。帐户:< ELLIDED:-238957088>,应用:com.google.android.gms,服务:oauth2:https://www.googleapis.com/auth/games
dkq:长时间无法使用凭据。 $:b $ b在dkr.a(:com.google.android.gms:3101)
在dje.a(:com.google.android.gms:397)
在djd.a(: com.google.android.gms:31369)
在djd.a(:com.google.android.gms:313)
在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)
在dfw.a(:com.google.android.gms:210)
在dgf.a(:com.google.android.gms:1498)
at dge.a(:com.google.android.gms:909)
at dge.e(:com.google.android.gms:523)
在dgd.a(:com.google.android.gms:37)
在dhm.getAuthToken(:com.google.android.gms:178)
在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 )
基于此线程,您会看到一个错误,可能是因为用户的帐户已连接到托管帐户和一个Google帐户,并且可能每个帐户都有不同的密码。身份验证服务器目前无法很好地处理此问题。按照此使用Google API客户端库for Java连接Google Drive 教程。
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...
//使用OAuth2的Google帐户
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 ();
...
}
您也可以检查以下相关问题:
- 错误的认证错误Rails连接到谷歌驱动器
- Google Drive:403验证失败
I'm having a problem with the Google Drive REST v3 android API. The OAuth token is getting a BAD_AUTHENTICATION result. Here's the connection code I'm using. It can also be noted that the OAuth consent screen is not showing up, and after a short period of time, I get the BAD_AUTHENTICATION result. Am I required to manually pass a refresh token to the server or something?
// 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's 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)
解决方案Based from this thread, you're getting an error maybe because the user's account is attached to both a hosted account and a Google account, and probably it has different passwords for each The authentication servers currently do not handle this well. Follow this Connecting to Google Drive with Google APIs Client Library for Java tutorial.
@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(); ... }
You can also check on these related issues:
Hope this helps!
这篇关于Android Drive API OAuth BAD_AUTHENTICATION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!