如何使用JWT访问Google Androidpublisher API?

时间:2019-03-20 09:41:42

标签: google-api in-app-purchase jwt google-oauth in-app-billing

因此,这里有一种使用JWT令牌对Google API服务进行授权的方法:Service account authorization without OAuth

我尝试遵循以下说明:

1. Create a service account. Be sure to keep the JSON file you get when you create the account.

完成。

2. Get the API's service name and API name from the service definition file on GitHub.

我去Google APIs GitHub repository并开始搜索。我需要访问Androidpublisher API。因此,首先,我尝试检查文件夹的结构和不足,以及所需API的位置。没运气。然后,我尝试通过关键字“ androidpublisher”和“ android”搜索* .yaml文件的整个仓库。再没有运气了。我实际上已经通过关键字“ publisher”找到了一些内容:它是pubsub API,但似乎不是我想要的。

好,让我们再读一遍:

If the API you want to call has a service definition published in the Google APIs GitHub repository, you can make authorized API calls using a JWT instead of an access token.

因此,基本上,这意味着任何可能会或可能不会在此发布API。

在此SO question中,我找到了一种使用带有凭据和Java client library for Google Play Developer API的JSON文件授权Androidpublisher API的方法:

private static Credential authorizeWithServiceAccount() throws IOException {
    log.info("Authorizing using Service Account");
    try (FileInputStream fileInputStream = new FileInputStream(JSON_PATH)) {
        return GoogleCredential.fromStream(fileInputStream, HTTP_TRANSPORT, JSON_FACTORY)
                .createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER));
    }
}

所以我认为存在一种使用JWT令牌在此处进行授权的方法。但是我不能使用Java库,因为我的服务将在C ++上运行。不幸的是,谷歌没有为C ++开发人员提供库。

有一次我非常绝望,以至于我什至试图在Java上编译该代码并运行它,只是为了查看它正在将HTTP请求发送到哪里(使用调试器或Wireshark)。但是我不是Java开发人员,在解决了一个依赖性问题一个小时之后,我在运行代码时仍然遇到“缺少Java Key Store”(或类似问题)的问题。所以我放弃了。

所以我的最后一个问题是: Androidpublisher API的Service nameAPI name是什么?

我本应该能够在this instruction的第二步中检索到那些值。但是我失败了。我觉得那是我目前无法完成的唯一信息。

1 个答案:

答案 0 :(得分:1)

我找到了一种无需即可访问Adndoidpublisher API的方法,

2. Get the API's service name and API name from the service definition file on GitHub.

我可以create a JWT token,然后使用它来获取API访问令牌。 HTTP/REST标签中的here描述了此方法。

然后我就可以访问ordinary way中的API。