How do I resolve androidpublisher error 401 when implementing Google IAP server side?

36 Views Asked by At

I am implementing the Google InAppPurchase function. On the Spring Boot server side, the dependency was configured as follows.

implementation "com.google.api-client:google-api-client:1.33.0"
implementation 'com.google.auth:google-auth-library-oauth2-http:1.6.0'
implementation 'com.google.apis:google-api-services-androidpublisher:v3-rev20230313-2.0.0'
implementation group: 'com.google.http-client', name: 'google-http-client-jackson2', version: '1.41.7'

If you pay on the Android front, you will also receive the purchaseToken. Receipt validation is performed using packageName, productId, and purchaseToken on the Spring Boot server side.

AndroidPublisher publisher = googleCredentialsConfig.androidPublisher();
AndroidPublisher.Purchases.Products.Get get = publisher.purchases().products()
            .get(receiptRequest.getPackageName(), receiptRequest.getProductId(), receiptRequest.getPurchaseToken());

ProductPurchase purchase = get.execute();

However, when you perform get.execute(), the following error appears.

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

I don't know why this error occurs. When I search, it says what to do in [API access] in [Settings] on the [Google Play console], but when I go into the Play console, I don't see the API access page. I think I need to do some work in Google Cloud Platform (GCP), but I'm not sure. help.

0

There are 0 best solutions below