20

On getting a subscription status (https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get) API responds with

{
  "error": {  
    "errors": [   
      {    
        "domain": "androidpublisher",    
        "reason": "purchaseTokenNoLongerValid",    
        "message": "The purchase token is no longer valid."   
      }  
    ],  
    "code": 410,  
    "message": "The purchase token is no longer valid." 
  }
}

I couldn't find any mention of "purchaseTokenNoLongerValid" or "The purchase token is no longer valid" in context of Android publisher API, neither in docs nor in Google search.

I can guess what this error means, but better to know exactly, and anyway, what should I do with the subscription after this error?

ksimka
  • 1,394
  • 9
  • 21

4 Answers4

28

I received this message recently from the Google Play team, so HTTP status 410 will be the default response for subscriptions expired for more than 60 days.

Starting on May 21, 2018, Purchases.subscriptions.get will return HTTP status 410 with no content in the response for subscriptions that have been expired for 60 days or more. There is no change for active subscriptions or canceled subscriptions that have not yet expired or been expired for fewer than 60 days.

Visit the Android developers website for more information on how to verify purchases.

And indeed, I tried it at May 22 and got a response with status 410 and this body:

{
    "error": {
        "errors": [
            {
                "domain": "androidpublisher",
                "reason": "subscriptionPurchaseNoLongerAvailable",
                "message": "The subscription purchase is no longer available for query because it has been expired for too long."
            }
        ],
        "code": 410,
        "message": "The subscription purchase is no longer available for query because it has been expired for too long."
    }
}
zafeiris.m
  • 4,339
  • 5
  • 28
  • 41
  • 4
    For the sake of Google search hits: it appears the response reason has changed to `subscriptionPurchaseNoLongerAvailable` with the message `The subscription purchase is no longer available for query because it has been expired for too long.` – mroach May 23 '18 at 13:57
  • @mroach thank you, I updated the answer with the full response – zafeiris.m May 24 '18 at 09:20
  • 2
    Amazingly undocumented feature by Google. Thanks a ton for this answer! – Torsten Ojaperv Feb 26 '19 at 17:16
6

I got an official response from Google Play support team about this error:

I took a look and the order ID you provided is associated with an account that has now been deleted. This is why it does not pass verification. This is a good example of the licensing system working as intended.

You may feel free to simply ignore this subscription.

And another email after I ask for more details:

Technically, the subscription is still active even though it's not attached to an account - hence, it does not show as cancelled. We're aware it's confusing not to receive a clear message about the account's status and just get an error back, though. This is an area of our product we're still actively working on.

What you can do is use the API to revoke the subscription, which is fine to do now that you have confirmation that the account is gone. Then it will read as cancelled and will no longer throw an error when making an API call.

Community
  • 1
  • 1
guillaume-tgl
  • 2,749
  • 3
  • 23
  • 30
1

I think Google just had updated their API, and start to response with status code 410 to requests with purchase token which is not renewed a long time (no subscription renew). So they sure at 100% that subscription with such token will not be renewed.

So, it's a good news, because now you able detect such purchase tokens, and do not send them to validation at all, if you did it before.

Stafox
  • 1,007
  • 14
  • 25
-1

Looks like purchase token is revoked when user changes his password from Google account or deletes account. Then this error will be returned on every request.

Here is a list of reasons for OAuth2 tokens — https://developers.google.com/identity/protocols/OAuth2#expiration , but I feel it's quite the same situation.

  • The user has revoked access.
  • The token has not been used for six months.
  • The user changed passwords and the token contains Gmail scopes.
  • The user account has exceeded a certain number of token requests.
ksimka
  • 1,394
  • 9
  • 21