我目前正在开发一个应用程序,我已经在其中集成了 GooglePlus Api。我的应用程序使用谷歌帐户成功登录,但我无法获取访问 token 。我遵循了 developer.google.com 提供的步骤以及为 Stackoverflow 中发布的类似问题提供的解决方案。
例如。
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String token = null;
try {
token = GoogleAuthUtil.getToken(
MainActivity.this,
mGoogleApiClient.getAccountName(),
"oauth2:" + SCOPES);
} catch (IOException transientEx) {
// Network or server error, try later
Log.e(TAG, transientEx.toString());
} catch (UserRecoverableAuthException e) {
// Recover (with e.getIntent())
Log.e(TAG, e.toString());
Intent recover = e.getIntent();
startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
} catch (GoogleAuthException authEx) {
// The call is not ever expected to succeed
// assuming you have already verified that
// Google Play services is installed.
Log.e(TAG, authEx.toString());
}
return token;
}
@Override
protected void onPostExecute(String token) {
Log.i(TAG, "Access token retrieved:" + token);
}
};
task.execute();
mGoogleApiClient.getAccountName()
方法对我不起作用(即当我键入 mGoogleApiClient.
时,没有这样的方法称为 getAccountName()
选择)。
这是因为我在 fragment 中实现了 GoogleApi 吗?或者
有什么原因吗。
请帮我解决这个问题。 谢谢
最佳答案
最后我找到了我要找的东西,我使用 Plus.AccountApi.getAccountName(mGoogleApiClient)
而不是 mGoogleApiClient.getAccountName()
并且成功了。
关于android - 从 Android 中的 GoogleApiClient 获取我的应用程序的访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26073699/