【问题标题】:How to get access to Google Androidpublisher API using JWT?如何使用 JWT 访问 Google Androidpublisher API?
【发布时间】:2019-03-20 09:41:41
【问题描述】:

因此,有一种方法可以使用此处描述的 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”在整个 repo 中搜索 *.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 密钥库”(或类似问题)的一些问题。所以我放弃了。

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

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

【问题讨论】:

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


    【解决方案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了。

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      相关资源
      最近更新 更多