我目前正在开发应用程序,并且已将GooglePlus Api集成到其中。我的应用程序已成功使用Google帐户登录,但是我无法获取访问令牌。我遵循了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吗?要么
有什么理由吗?
请帮我解决这个问题。谢谢
终于我找到了我想要的东西,我用了Plus.AccountApi.getAccountName(mGoogleApiClient)
而不是,mGoogleApiClient.getAccountName()
结果得到了解决。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句