私はGdriveサービスにログインするAndroidアプリに取り組んでおり、ユーザーに許可を与えるように求めた後、トークンを保存し、gdriveサービス自体にコンテンツを要求するバックエンドに送信します. 以前は、AccountManager を使用してログインしていましたが、数週間前に Google から、承認プロセスを Google Play サービス ライブラリに移動するよう求めるメールを受け取りました。トークンの取得に問題があります。コードは次のとおりです。
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(myApp.getApplicationContext(), DriveScopes.DRIVE);
Account[] mAccounts = credential.getAllAccounts();
ログインするアカウントを選択した後、リスナーは次のようにします。
Account account = mAccounts[position];
credential.setSelectedAccountName(account.name);
new GetDriveServiceTask().execute(credential);
private class GetDriveServiceTask extends AsyncTask<GoogleAccountCredential, Void, Void> {
protected Void doInBackground(GoogleAccountCredential... credentials) {
try{
GoogleAccountCredential credential = credentials[0];
String token = credential.getToken();
} catch (UserRecoverableAuthException e) {
UserRecoverableAuthException exception = (UserRecoverableAuthException) e;
Intent authorizationIntent = exception.getIntent();
startActivityForResult(authorizationIntent,REQUEST_PERMISSIONS);
}
ユーザーがコマンド credential.getToken(); の前に自分のアカウントへのアクセスを許可したときに問題が発生しています。「1/SGvUDUNnRG8wVs_REISKx1xuupbwAKeEQ5fHXH-rbOk」のような更新トークンと思われるもののみを提供します...どうすればこれからアクセストークンを取得できますか?
ここで説明されているように、URL「https://accounts.google.com/o/oauth2/token」への Post 呼び出しを試みました: https://developers.google.com/accounts/docs/OAuth2WebServer#refreshしかし、私は毎回unauthorized_clientを取得しています...
ここで立ち往生しており、電子メールには、AccountManager メソッドは 2 月 1 日に機能しなくなると書かれていました...
前もって感謝します!