Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get access to Google Play Developer API using Service Account flow?

Tags:

google-oauth

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.

like image 365
ludd Avatar asked Dec 18 '13 17:12

ludd


People also ask

How do I access my Google Play store API?

Navigate to “IAM & Admin” and there to “Service Accounts”, if this view is not already open. The title should show “Service accounts for project Google Play Android Developer”. Here you'll see other service accounts if you already have some in place.


1 Answers

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


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

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


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.

like image 189
Alex Lipov Avatar answered Oct 06 '22 20:10

Alex Lipov