【问题标题】:Is it possible to get access to Google Play Developer API using Service Account flow?是否可以使用服务帐户流程访问 Google Play Developer API?
【发布时间】:2014-01-06 23:32:40
【问题描述】:

是否可以使用服务帐户流访问 Google Play Developer API? 此处的文档 (https://developers.google.com/android-publisher/authorization) 仅提及 OAuth 2.0 Web 服务器流程。但不清楚是举例还是限制。

如果可能的话,最好提供一些指向工作示例的链接。因为我无法通过“此开发者帐户不拥有该应用程序”的响应。

【问题讨论】:

    标签: google-oauth


    【解决方案1】:

    可以使用服务帐户流访问 Google Play Developer API。


    Official sample 展示了如何使用service account emailp12 file 使用服务帐户进行授权。
    relevant credential creating code 如下所示:

    private static Credential authorizeWithServiceAccount(String serviceAccountEmail)
            throws GeneralSecurityException, IOException {
        log.info(String.format("Authorizing using Service Account: %s", serviceAccountEmail));
        // Build service account credential.
        GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(HTTP_TRANSPORT)
                .setJsonFactory(JSON_FACTORY)
                .setServiceAccountId(serviceAccountEmail)
                .setServiceAccountScopes(
                        Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
                .setServiceAccountPrivateKeyFromP12File(new File(SRC_RESOURCES_KEY_P12))
                .build();
        return credential;
    }
    

    AzimoLabs 的人们写了一个post,他们使用这种方法检索商店评论。他们还 open-sourced 他们的工具。


    您还可以使用 JSON 密钥类型通过服务帐户进行授权:

    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));
        }
    }
    

    更详细的说明可以在here找到。

    【讨论】:

    • 终于! ;) 这是一个有点过时的问题。谷歌似乎已经解决了我在 2013 年遇到的问题。几年后,后端授权的问题要少得多......
    猜你喜欢
    • 2014-05-30
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2018-10-06
    • 2013-08-30
    • 1970-01-01
    相关资源
    最近更新 更多