Google Android 发布者 API 响应“410 purchaseTokenNoLongerValid”错误

Google Android publisher API responds with "410 purchaseTokenNoLongerValid" error

获取订阅状态时 (https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get) API 响应

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

我在 Android 发布者 API 的上下文中找不到任何提及 "purchaseTokenNoLongerValid" 或 "The purchase token is no longer valid" 的内容,无论是在文档中还是在 Google 搜索中.

我能猜到这个错误是什么意思,但最好准确地知道,无论如何,在这个错误之后我应该如何处理订阅?

当用户从 Google 帐户更改密码或删除帐户时,购买令牌似乎已被撤销。那么每次请求都会返回这个错误。

这里列出了使用 OAuth2 令牌的原因 — https://developers.google.com/identity/protocols/OAuth2#expiration,但我觉得情况完全相同。

  • 用户已撤消访问权限。
  • 令牌已六个月未使用。
  • 用户更改了密码并且令牌包含 Gmail 范围。
  • 用户帐户已超过一定数量的令牌请求。

我认为 Google 刚刚更新了他们的 API,并开始用状态码 410 响应购买令牌的请求,该令牌很长时间没有更新(没有订阅更新) ).因此,他们 100% 确定不会续订使用此类令牌的订阅。

所以,这是个好消息,因为现在您可以检测到此类购买令牌,如果您以前这样做过,则根本不需要将它们发送给验证。

我从 Google Play 支持团队得到了关于此错误的官方回复:

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.

在我询问更多细节后又发了一封邮件:

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.

我最近从 Google Play 团队收到了这条消息,因此 HTTP status 410 将是订阅过期超过 60 天的默认回复。

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.

确实,我在 5 月 22 日尝试过,并收到了状态为 410 和此正文的回复:

{
    "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."
    }
}