google-api-dotnet-client: The current user has insufficient permissions to perform the requested

I faced with a problem with subscription verification on the server side. I’ve already read tons of articals and manuals but issue is still there. I’ve created Service Account, linked project with Google Play Console, added Api, added user for service account and granted it admin. previlege, but when I run my sample app. it returns me “The current user has insufficient permissions to perform the requested”. I found similar issue for nodeJS. It seems that I have to wait about 24 hours…

Did anyone faced with the problem?

Code:

static void Main(string[] args)
{
    var privateKey = "{\n  \"type\": \"service_account\",\n  \"project_id\": \"....";

    var credential = GoogleCredential.FromJson(privateKey)
        .CreateScoped("https://www.googleapis.com/auth/androidpublisher");

    var accessToken = ((ITokenAccess) credential).GetAccessTokenForRequestAsync().GetAwaiter().GetResult();

    const string PACKAGE_NAME = "....";
    const string PRODUCT_ID = "week_auto_subscription_test";

    var token = "gpnmf....";

    var uri = new Uri($"https://www.googleapis.com/androidpublisher/v3/applications/{PACKAGE_NAME}/purchases/subscriptions/{PRODUCT_ID}/tokens/{token}");
    var client = new HttpClient();

    var request = new HttpRequestMessage(HttpMethod.Get, uri);
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

    var response = client.SendAsync(request).GetAwaiter().GetResult();
    
    Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
    Console.ReadKey();
}

Result:

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19

Most upvoted comments

I was getting below response when verifying purchase using service account to call purchase API.

Status: 401, message: The current user has insufficient permissions to perform the requested operation.

The reason was that I not included the service account credentials in Google Play console. Settings -> Developer account -> API Access are now not showing on the Google Play Console.

So below are the steps I perform after that to get response from Purchase API:

1. In the Google Cloud Console go to Service Accounts and create.

a1

2. Assign the Rule.

a2

3. Go to the Users & Permissions page on the Google Play Console and Click Invite new users.

a3

4. Put an email address for your service account in the email address field.

a4

5. Add an app to grant the permissions and then click on manage permissions.

a5

6. Grant the necessary rights to perform actions and click Invite user.

To use the Google Play Billing APIs, you must grant the following permissions:

• View financial data, orders, and cancellation survey responses

• Manage orders and subscriptions

a6

After these steps create or update the existing product/subscription name, country it will affect instantly without any delay. This is needed because you created product/subscription id before granting permissions.

Reference and more details

Done

@tariqali786 thanks for this info: “After these steps create or update the existing product/subscription name, country it will affect instantly without any delay”. It worked for me like a charm.

About 48 hours has been elapsed and manually verification start works as expected. But verification via Google.Apis.AndroidPublisher.v3 still not works.

@tariqali786 Thank so much!!, I was missing the “Invite new users” part and use the email of service account,