我需要获取访问令牌并将其发送到服务器。使用该访问令牌服务器应获取所有用户详细信息,如姓名,个人资料图片和电子邮件。Google plus登录访问令牌retriew
我可以使用Scopes.PLUS_LOGIN和Scopes.PLUS_ME访问令牌,但与访问令牌服务器无法获得用户的电子邮件。
这里是我的代码:
@Override
public void onConnected(Bundle arg0) {
mSignInClicked = false;
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String token = null;
String scope = "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_ME;
try {
token = GoogleAuthUtil.getToken(
getApplicationContext(),
Plus.AccountApi.getAccountName(mGoogleApiClient),
scope);
appUser.setToken(token);
} catch (IOException transientEx) {
// Network or server error, try later
Log.e(TAG, transientEx.toString());
} catch (UserRecoverableAuthException e) {
// Recover (with e.getIntent())
} 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:" + appUser.getToken());
// Get user's information
}
};
}
是否有人知道如何解决这个问题?
我想使用您的代码。你能解释我什么是appUser和setToken()吗? –
它是POJO类和二传手和吸气剂。你可以保存没有的结果。 – Zookey