Reputation: 81
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.
Upvotes: 8
Views: 1857
Reputation: 13958
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.
Upvotes: 1