如何发布令牌GoogleAuthUtil.getToken()从android应用php web服务器


how to post token of GoogleAuthUtil.getToken() from android app php web server

我用以下代码行获得标记:

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;
}

我怎么能张贴代码收到我的php web服务器从我的Android应用程序?如何验证服务器上的令牌和交换到谷歌的访问令牌,之后php web服务器将返回xml和如何android可以立即从服务器接收xml数据。

谢谢!

在Google+登录文档中有关于如何将令牌传递给服务器的描述。

基本上,你使用GoogleAuthUtil。getToken,添加服务器的初始客户端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);
  ...
}

然后将接收到的代码发送到服务器,服务器必须将其交换为服务器的访问和刷新令牌。