是否可以使用“服务帐户"流程访问Google Play开发者API?

问题描述:

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

Is it possible to get access to Google Play Developer API using Service Account flow? Documentation here (https://developers.google.com/android-publisher/authorization) mentions only OAuth 2.0 Web Server flow. But it's unclear whether it is example or restriction.

如果可能的话,提供一些到工作示例的链接将非常有用.原因我无法摆脱此开发人员帐户不拥有该应用程序"的响应.

If it is possible it will be great for some link to working example to be provided. Cause I wasn't able to get past "This developer account does not own the application" response.

使用服务帐户流访问Google Play开发者API是可能.

It is possible to access the Google Play Developer API using Service Account flow.

官方示例显示了如何使用p12 file.

Official sample shows how to authorize with Service Account using service account email and p12 file.
The relevant credential creating code looks as following:

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的朋友写了一条帖子他们使用此方法检索商店评论.他们还开源他们的工具.

Folks at AzimoLabs wrote a post where they retrieving store reviews using this method. They also open-sourced their tool.

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

You can also authorize with Service Account using JSON key type:

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

更详细的说明可以在此处找到.

More detailed instructions can be found here.