我有一个函数尝试获取令牌来查询 Drive API:
private void getAuthTokenBlocking() {
try {
Account account = AccountManager.get(sActivity).getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE)[0];
sToken = GoogleAuthUtil.getToken(sActivity, account.name, DriveScopes.DRIVE_READONLY);
} catch (GooglePlayServicesAvailabilityException playEx) {
Dialog alert = GooglePlayServicesUtil.getErrorDialog(
playEx.getConnectionStatusCode(),
sActivity,
AUTH_REQUEST_CODE);
alert.show();
} catch (UserRecoverableAuthException userAuthEx) {
userAuthEx.printStackTrace();
} catch (IOException transientEx) {
transientEx.printStackTrace();
} catch (GoogleAuthException authEx) {
authEx.printStackTrace();
}
}
但我总是收到以下错误:
com.google.android.gms.auth.GoogleAuthException: Unknown
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
我已经尝试了所有我能看到的解决方案,包括在范围前加上“oauth2:”。