Google 播放 api - purchases.products.get 购买验证给出 401 OAuth2 错误

Google play apis - purchases.products.get for purchase validation gives 401 OAuth2 error

我的目标是使用 服务器端 上的服务帐户从 googleapi 获取购买的商品。

Method: purchases.products.get api 需要 oauth2 身份验证。

因此我从客户端创建了一个 oauth2 令牌-secret.json 我是从 consolce.cloud.google 提供的- 在我的服务器端 后端 java spring申请.

    GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("src/main/resources/client_secret.json")).createScoped("https://www.googleapis.com/auth/androidpublisher");
    googleCredentials.refresh();
    AccessToken accessToken = googleCredentials.getAccessToken();

我生成的令牌就像'ya29.c.b0AXczHcuLszNI................' 它以多个点结尾我不知道为什么。

https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/products/{productId}/tokens/{token}

获得令牌后,我对这个 URL 执行 GET 请求。 我收到以下错误:

"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",

为什么我的令牌不起作用?我的使用方式,有错吗? And/or oauth2 token 生成方式是不是错了?

访问令牌作为授权发送header。访问令牌应以不记名一词为前缀,因为它是不记名令牌。