3

When I try to call https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token} from my backend server to verify a purchase I receive :

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
      {
        "message": "Login Required.",
        "domain": "global",
        "reason": "required",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"
  }
}

How can I authenticate from my backend server (so without any user interface)? Is there any way to create an API key somewhere and use it to authenticate?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
zeus
  • 12,173
  • 9
  • 63
  • 184
  • Please edit your question and include your code. You need to be authorized with Oauth2 to run this request. Your missing the authorization header with a bearer token – Linda Lawton - DaImTo Oct 23 '20 at 12:15
  • @DaImTo I don't want to use Oauth2 but instead use an api key. seam it's possible but I don't know how to do it :( – zeus Oct 23 '20 at 13:57
  • 1
    The method you are using requires Oauth2 in order to access private user data, APIkeys are only for accessing public data. – Linda Lawton - DaImTo Oct 26 '20 at 09:21

1 Answers1

2

The error message

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

States that authorization is required.

If you check the documentation for Method: purchases.subscriptions.get

You will notices that it states that this method requires authorization with the following scope

enter image description here

Assuming this is an account you the developer control and you only want to access this single account you should look into using a service account for authorization. Documentation here Using a service account

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449