Search code examples
javakotlingoogle-oauthgoogle-api-java-clientgoogle-play-developer-api

Google Play Developer API - 400 Invalid Value - InAppPurchases


My question is similar to this one. However, I am using the API Java Client Library with a service account, making calls to the API from my server.

My code is following this guide, which is very simple. However, I can't seem to get an appropriate error for my request. This is how I build my AndroidPublisher:

val credential = GoogleCredential.fromStream(FileInputStream(
        "/path/to/json"
)).createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))

androidPublisher = AndroidPublisher.Builder(httpTransport, JSON_FACTORY, credential)
        .setApplicationName(packageName)
        .build()

Where the JSON is generated from the Developer Console, under Service Accounts. This is how I make my request:

androidPublisher.purchases().subscriptions().get(packageName, "valid-sku", "invalid-token").execute()

My subscription ID is valid but my token is invalid. I expect an error such as "invalid token" in the response. However, what I get is:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Value",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Value"
}

Is that a generic error because of the invalid token or is it an authentication issue? If it an authentication issue, how do I solve it? If it is an invalid token issue, how am I supposed to know?

Some more information:

  • I get the same error when trying to make that call from the API Explorer as well (this time using a Client ID and API Key instead of Service Account).
  • I have not delegated domain-wide access to the service account. Do I have to for some reason?
  • I can successfully make other calls to the API such as inappproducts.list

Solution

  • So, the reason that happened was just because the purchaseToken I was using was wrong.

    I did not expect that to be the reason as I thought that in the case of an invalid token, I would receive a "token invalid" error (or something similar). As it turns out, the responses given by Google are pretty inconsistent (a 404 could also be given for an invalid token).