Review-Reporter: Part 1 - Connecting to Google Play

We would like to share with you our small java project called Review-Reporter. A bot assistant that enhances our communication with users by keeping us up to date their feedback, scheduling and allowing instant responses.

How does it work?

Review-Reporter repeats in fixed interval ongoing actions:

  • Access Google Play Store and fetches recent user reviews.
  • Checks which reviews has star rating with value three or less.
  • Connects to Firebase (online database) to check if any of those reviews were already highlighted to us.
  • Sends unreported reviews to our Slack channel with “Reply to review” option added.
  • Create Jira issue for every unreported review.
  • Update/inform Firebase about new reported reviews.

As you can see there are many services connected together. We would like to go through each part of ReviewReporter to show you how to connect to each service separately and finally how to join everything together.

Setup Google Play Account

Google allows you to access your Google Play data with Reply to Reviews API. Google documentation is quite a maze. There are many ways to tackle this problem and they tend to be grouped together and redirect you to other pages which are groups of other tutorials, setups and possibilities. In a result you might end up losing “right” trail which you decided to follow at start. That’s why we will list necessary minimum of steps in order to connect.

  • To gain access to Google Play, first thing you need to take care of is authorisation. Google allows you to either use OAuth (which requires you to ask for access token and refresh it every two hours) or Service Account - impersonate yourself as one of Google Play users assigned to your project (which doesn’t need any tokens). In our case we have decided to use Service Account.
  • To create Service Account go to API Access page in Google Play Developer Console and click on “Create Service Account” button. You will enter Service Accounts page for your project.
  • There you need to press “Create Service Account” again and enter name of your account.
  • Additionally you want to check “Enable G Suite Domain-wide Delegation” (allows you to access user data programatically without previous manual authorisation).
  • Furthermore check “Furnish a new private key” which is an unique file you will need to provide during connection of your app/service with Google. You are allowed to pick either JSON or P12 type of file. In our case we used P12 file.
  • If you have set up everything correctly, then when you return to API Access page, you should see your account listed:
  • Additionally when you click on “View in Google Developers Console”, you will move to Credentials page. You should see OAuth 2.0 client created for your service account which is a proof that G Suite Domain-wide Delegation works. Your service account key which you have furnished should also be listed there:
You should see OAuth 2.0 client created for your service account which is a proof that G Suite Domain-wide Delegation works.
  • So now we have service account created. Another thing that needs to be done is granting it permissions to access reviews on Google Play Store. Press “Grant access” and you will be moved to User accounts & rights page in your Google Play Developer Console. All permissions you need for this service account is Reply to reviews. Role will be picked automatically. After you click “Save” you should end up with following setup:

And your setup on web side is complete. To sum up what we have done is:

  1. We have create Service Account which impersonates real user account assigned to your project.
  2. We have granted Service Account access to view and reply to reviews of your project.
  3. We have granted Service Account a G Suite Domain-wide Delegation which allows us to access all data (from code) that created Service Account is able to see (reviews) if we provide unique, private key file.

Connection to Google Play

Again there are many ways to perform authorisation and access reviews depending on platform you would like to use. In our case we are using Java.

Google has created Google Play Developer API Client Library that makes interaction with Google Play accounts possible. You can add it to your project from maven. What you need to be wary of is that what we want to use v2 version of Google Play Developer API and there is still documentation for v1 version available which offers less functionalities and might make you confused.

Object which allows us to access Google Play account is called AndroidPublisher. It is a factory class that provides API services responsible for handling REST requests in scope of specific module (Edits, Inapproducts, Entitlements, Purchases and Reviews).

There is an example code, given to us by Google, how to get instance of AndroidPublisher in our code. We also have created our own helper class:

It is very simple. You need to provide:

  • Application name - in case you wanted to access few apps in the same project, this is used as an information to tell apart few instances of AndroidPublishers. It is also used as a header in API requests performed by specific AndroidPublisher.
  • Service Account email - full service account email that we have created in previous step.
  • Credentials - during creation of Service Account we have furnished private key that allows us to be programmatically authorised/impersonated as user of Google Play. You need to insert absolute path to that file in your workspace.
  • HttpTransport - helper class which can be created by newTrustedTransport() method.
  • JsonFactory - helper class which can be created by newJacksonFactory() method.

In a nutshell if you are using our helper then additionally you need two strings and credential file. Thats all. There is a code where we have put AndroidPublisherBuilder to action.

Finally when you have correctly received instance of AndroidPublisher. You can fetch reviews from your project.

Your quota size for fetching reviews from Google Play equals 60 requests/per hour.

There you can find example of response with all possible fields to which you have access from Review class of AndroidPublisher.

Final words

This article shows how to connect to your Google Play project and fetch reviews in form of list of Java objects. You can use this data to connect with any other services you need. We report every review to our team Slack channel. Additionally we create Jira issues for every review with (starRating ≤ 3). That way none of our users problems is ignored and we can reach them instantly :)

We will follow it in the next article.

You can also check our complete project code located at our AzimoLabs GitHub.


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.