我有一个客户端和服务器应用程序,一旦在客户端(android)上验证后,需要在服务器端访问用户 g+ 配置文件
我通过这个在客户端获得了一个 ID 令牌
@Background
void getAccessToken() {
    String scopes = "audience:server:client_id:xxxxxxxxxxxxx.apps.googleusercontent.com";
    Log.d(TAG,scopes);
    try {
        accessToken = GoogleAuthUtil.getToken(this,mPlusClient.getAccountName(),scopes);
        Log.d(TAG,accessToken);
        getPlusFriends();
    }
    catch (IOException transientEx) {
        Log.e(TAG, transientEx.getMessage());
        return;
    }
    catch (UserRecoverableAuthException e) {
        Log.e(TAG, e.getMessage());
        accessToken = null;
    }
    catch (GoogleAuthException authEx) {
        Log.e(TAG, authEx.getMessage());
        return;
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
这将给我一个长 ID 令牌,如本博客http://www.tbray.org/ongoing/When/201x/2013/04/04/ID-Tokens中所述
我想我应该将该令牌发送到我的服务器,在那里我需要做一些事情将它变成一个 access_token。我可以验证 id 令牌吗?发送 curl 请求到
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
它返回一个像这样的json字符串
{
"issuer": "accounts.google.com",
"issued_to": "xxxxxxxxxxxxxx.apps.googleusercontent.com",
"audience": "xxxxxxxxxxxxxx.apps.googleusercontent.com",
"user_id": "123456",
"expires_in": 3362,
"issued_at": 1382577073,
"email": "myemail@something",
"verified_email": true
}
php服务器
\Config::load('google_api', 'google');
 $key = Config::get('google.client_id');
 $secret = Config::get('google.client_secret');
 $scopes = Config::get('google.scopes');
 $client = new Google_Client();
 $client->setClientId($key);
 $client->setClientSecret($secret);
 $client->setScopes($scopes);
 $client->setState('offline');
 $client->authenticate($token);
其中issued_to 是我在Google API 控制台中的Android 应用程序的客户端ID,而受众是我的Web 应用程序的客户端,我认为到目前为止似乎是正确的。
所以现在我正在使用 php 客户端,并不确定从那里做什么。我尝试使用 id 令牌验证 api 客户端,但我只收到错误 400 - 获取 OAuth2 访问令牌时出错,消息:'invalid_grant'
我不确定是否应该尝试使用该 ID 令牌对 PHP Google+ 客户端进行身份验证,或者如何将其交换为访问令牌