如何使用JWT访问Google Androidpublisher API?

问题描述 投票:0回答:1

因此,有一种方法可以使用此处描述的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。所以,起初我已经尝试检查文件夹结构和underestand所需API的位置。没运气。然后我试图通过关键字“androidpublisher”和“android”搜索整个回购的* .yaml文件。再没有运气。我实际上通过关键字“发布者”找到了一些东西:它是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 ++上运行。不幸的是,Google没有为C ++开发人员提供库。

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

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

我应该能够在this instruction的第二步中检索这些值。但我失败了。我觉得这是我现在所缺少的唯一一条完成任务的信息。

google-api in-app-purchase jwt google-oauth in-app-billing
1个回答
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访问令牌。在here标签中描述了HTTP/REST的方法。

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

© www.soinside.com 2019 - 2024. All rights reserved.