【发布时间】:2014-09-27 22:11:10
【问题描述】:
我目前正在开发一个应用程序,并且我已经在其中集成了 GooglePlus Api。我的应用程序使用谷歌帐户成功登录,但我无法获取访问令牌。我按照 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() 可供选择)。
这是因为我在片段中实现了 GoogleApi 吗?或
这有什么原因吗。
请帮我解决这个问题。 谢谢你
【问题讨论】:
标签: android google-plus access-token