hafiz031
hafiz031

Reputation: 2720

How to get access_token for replying review in Play Developer API?

This link: Reply to Reviews describes the way to retrieve and reply to reviews. The Google Play Developer Reply to Reviews API allows us to view user feedback for our app and reply to this feedback. But I am finding it difficult to get the authorization token. It says I should have got this when I get access to the API.access_token

But after going to the link, I didn't find too many information on this, rather, it has another link which takes me to the page where I have already created a service account.

After summarizing, my question is - I have created a service account and downloaded the key as JSON. But how to get this access_token the given snapshot asking for? The JSON file itself doesn't contain such access_token, rather it contains other information including type, project_id, private_key, client_id etc.

Upvotes: 0

Views: 1500

Answers (1)

hafiz031
hafiz031

Reputation: 2720

The process is not described directly in the link given in the question. Rather we will follow the steps mentioned in Play Developer API | Authorization

The whole process actually has two major steps:

  • Making a OAuth 2.0 client ID and downloading it.
  • Using client_id, client_secret and redirect_uris from this download JSON file to make API call.

Making OAuth 2.0 client ID and getting parameters

In order to do this:

  • Go to Google Play Console.

  • Use your play console account to login into it.

  • Make sure the right project is selected, at top there is a drop-down, where the correct project is supposed to be selected.

  • Now from + CREATE CREDENTIALS button create a OAuth Client ID and after successful creation you will find it listed under Credentials tab. The Credentials tab is at the left side of the page.

  • Now download the OAuth Client ID and it will be saved as a JSON file.

  • Open the JSON file and collect the client_id, client_secret and redirect_uris from there. Here redirect_uris will contain a list of URLs. One of them is http://localhost, we don't need it. Please take the other one, somewhat like urn:ietf:wg:oauth:2.0:oob.

Now the second step begins:

Make the API call

  • Now go to the first link I provided in the answer, i.e: Play Developer API | Authorization. We just did the first step under initial configuration. Now the second step begins. Make sure you are using the same browser where you are already logged-in on Google Play Console.

  • Now fill-up the fields in this link as mentioned in the documentation with the information we just got (client_id, client_secret, redirect_uris), remove the ... and put your redirect_uri and client_id there:

    https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=...&client_id=...
    
  • Now after filling up your credentials in this link provided paste this link to browser and go to this URL.

  • This may require you to authorize this request by signing in with your account (with the Google Play Console Account we are using so far).

  • After authorization you will be given a code parameter similar to 4/eWdxD7b-YSQ5CNNb-c2iI83KQx19.wp619..... (This is also mentioned in the documentation you may follow the steps there).

  • Now go to the step 4 in the documentation (following is a snapshot): getting access token replace the credentials which are here inside <..> (including < and >) with the information we so far collected. Here <the code from the previous step> is nothing but the code parameter 4/eWdxD7b-YSQ5CNNb-c2iI83KQx19.wp619.... we got.

  • Now make this API call. To make this kind of API calls you may need to use Bulk edit of Postman software (download and install the software). But if you are not comfortable with this Bulk edit, I am giving you a similar form data in the following snapshot. Just fill up the fields there in Postman and make the API call, (Please note that the method is selected POST): form_data_to_get_access_token Also you need not change the grant_type (its value is authorization_code).

  • Now clicking Send you should get the response which will contain access_token. Following is a snapshot of the response that comes with the access_token we are looking for (snapshot got from the documentation): successful response comes with access_token

  • This response will come only once (for a certain code), to get another response you may need another code. So, save this response as a JSON from Postman to use it further.

Now you are done! Use this access_token and make API calls to get reply to reviews. More details here. Also please note that you might not get any reviews at all with this call, as this reviews' responses only work for recent time. If you make some recent comment in Play Store under your desired app they will be returned but the older comments will not be returned as response and the response might be blank {} if there are no recent comments. As mentioned in the documentation:

Note: You can retrieve only the reviews that users have created or modified within the last week. If you want to retrieve all reviews for your app since the beginning of time, you can download your reviews as a CSV file using the Google Play Console.

Upvotes: 3

Related Questions