我使用以下代码行获取令牌:
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
"http://schemas.google.com/AddActivity");
String serverClientID = "648976189452-46n3cl4mi4p0vasdr3u1nh87706g0bis.apps.googleusercontent.com";
String scopes = "oauth2:server:client_id:" + serverClientID
+ ":api_scope:" + Scopes.PLUS_LOGIN;
String code = null;
LTDD_1051010005 contex = new LTDD_1051010005();
try {
code = GoogleAuthUtil.getToken(contex, // Context context
plusClient.getAccountName(), // String accountName
scopes, // String scope
appActivities // Bundle bundle
);
} catch (IOException transientEx) {
// network or server error, the call is expected to succeed if you
// try again later.
// Don't attempt to call again immediately - the request is likely
// to
// fail, you'll hit quotas or back-off.
return transientEx.getMessage();
} catch (UserRecoverableAuthException e) {
// Recover
code = null;
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should
// not be
// retried.
return authEx.getMessage();
} catch (Exception e) {
throw new RuntimeException(e);
}
return code;
}
如何从我的Android应用程序发布收到我的php网络服务器的代码? 如何验证服务器上的令牌并与Google交换访问令牌,之后php webserver将返回xml以及如何让andrroid立即从服务器接收xml数据。
谢谢!
答案 0 :(得分:0)
有关如何在Google+ sign-in documentation中将令牌传递到服务器的说明。
基本上,您使用 GoogleAuthUtil.getToken ,添加服务器的oauth客户端ID范围。
String scopes = "oauth2:server:client_id:<SERVER-CLIENT-ID>:api_scope:<SCOPE1> <SCOPE2>";
String code = null;
try {
code = GoogleAuthUtil.getToken(context, account, scopes, null);
...
}
然后将收到的代码发送到您的服务器,服务器必须将其交换为服务器的访问权限并刷新令牌。