我通过以下代码行获得 token :
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 网络服务器? 如何验证服务器上的 token 并与 Google 交换访问 token ,之后 php 网络服务器将返回 xml 以及 android 如何立即从服务器接收 xml 数据。
谢谢!
最佳答案
在 Google+ sign-in documentation 中有关于如何将 token 传递到您的服务器的描述。 .
基本上,您使用 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);
...
}
然后您将收到的代码发送到您的服务器,服务器必须用它交换服务器的访问和刷新 token 。
关于php - 如何从 Android 应用程序 PHP Web 服务器发布 GoogleAuthUtil.getToken() 的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22368077/