11

I am having trouble calling the Google Play Developer API.

I have followed all steps listed on https://developers.google.com/android-publisher/authorization . This includes

  1. Create Project and enabled Google Play Android Developer API (with my Google Play Console Account)
  2. Link the project through Settings > Developer Account > API Access
  3. Grant access to service account with finance permissions to the app through the Google Play Console.
  4. Create OAuth 2.0 Client Id, Client Secret, and Redirect URI credentials.
  5. Generate the Refresh Token and the Access Token by sending POST request.

Then, to call the purchases.subscriptions.get API, I used the following CURL command:

(https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions/get)

curl -X GET "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}" -H "Authorization: Bearer {access_token}" -H "Accept: application/json" --compressed

However, I am receiving the following error:

"error": {
    "code": 401, 
    "message": "The current user has insufficient permissions to perform the requested operation.", 
    "errors": [
      {
        "domain": "androidpublisher", 
        "message": "The current user has insufficient permissions to perform the requested operation.", 
        "reason": "permissionDenied"
      }
    ]
  }
}

I have read and implemented changes recommended in other posts such as

  1. added in-app product/subscription before granting permission or linking to service account
  2. opened "in-app products/subscription" and performed some updates
  3. Verified all Users and Permissions through Google Play Console
    • eg. service account is admin user
  4. waited over 48 hours to allow Google to propagate all access rights for APIs.

I have also tried calling the API through https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions/get#authorization-scopes but still no luck (get an error).

If anyone has any suggestions, that would be very much appreciated. Thanks.

James
  • 17,965
  • 11
  • 91
  • 146
vicki
  • 225
  • 2
  • 10
  • 1
    I am having the same issue. I see a lot of other users having this issue, but I tried everything in the other posts, but no luck. – James Nov 12 '20 at 16:50
  • Please eidt your question and include the code where you do this **Generate the Refresh Token and the Access Token by sending POST request.** As service accounts dont have refresh tokens i would love to see how you are managing that. – Linda Lawton - DaImTo Nov 13 '20 at 13:20
  • As stated in my question, I used the steps listed https://developers.google.com/android-publisher/authorization to generate the refresh token and access token. – vicki Nov 13 '20 at 14:31
  • There was a question about this topic: https://stackoverflow.com/questions/43536904/google-play-developer-api-the-current-user-has-insufficient-permissions-to-pe – xIsra Nov 19 '20 at 15:23
  • I have tried all suggestions listed in the above topic, but unfortunately still no luck. – vicki Nov 19 '20 at 16:41

4 Answers4

9

I faced a similar issue, the problem is in the settings we do in google developer project.

Refer to create-play-service-credentials for settings. Use the same primary account with which you created your in-app products.

Make sure you remove the previous one.

Link to a Google Developer Project Your Play Developer account needs to be linked to a Google Developer Project.

1a. Open the Settings > Developer account menus and select API access

API-access

1b. Select Link to connect your Play account to a Google Developer Project

choose-project-link

1c. Agree to the terms and conditions

agree-terms-conditions

2. Create Service Account Next we need to create a service account. This is done from the Google API Console.

2a. Select Create Service Account

create-service-account

2b. Create Service account key credentials

service-account

2c. Enter details for service account

enter-service-account-details

2d. Download your JSON credential: json-credentials

3. Grant Access

3a. In Play Console, select Grant Access on the newly created service account

grant-access

3b. Grant the following permissions:

apply-permissions

3c.Click Invite User at the bottom and send the invite

send-invite

You will be redirected to Users and Permissions where you should see your newly created service account as Active.

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
  • Service accounts no longer respond to api invites. Have you tested the last part? – Linda Lawton - DaImTo Nov 13 '20 at 13:22
  • I think you probably won't require that. It would work without that only. In my case I missed 3a and probably something else as well. That's why the second time I did stepwise and it worked. – Ankit Jindal Nov 13 '20 at 14:19
  • so I went through all this again, and created a new service account, but still get the same error :( – James Nov 17 '20 at 19:21
  • @James Did you even figure out why this guide didn't work? I've also followed it meticulously, and it also closely matches up with the official Android guides on how to verify receipts from Subscriptions. But I'm also not able to request verification, I also just get a "The current user has insufficient permissions to perform the requested operation.", despite the fact that my service account has all the permissions it could possibly need. Any ideas?? (I have also tried waiting 24 hours from when the permission was granted) – Falgantil Oct 31 '21 at 17:25
  • Sorry, never got it to work. Crazy complicated process that gives useless error messages. – James Nov 01 '21 at 18:14
1

30 hours later, I found what was wrong with mine, I didn't click the Add app button on the Users and Permissions page after adding the service account.

The invisible add app button

dhakim
  • 107
  • 5
0

I encountered the same issue. In my case, I was not using a key file (json one) for the granted service account on Google Play while verifying purchases on the back-end. I replaced the wrong key file with the one of granted service account on Google Play and it's working fine now.

mrdev
  • 617
  • 7
  • 8
0

In case someone else runs into this issue. If your app is still in testing don't forget to add the service account to your testers.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 22 '23 at 09:17