关于Google Play Developer API旧订阅token复现问题的咨询
Hey there, let's break down how to tackle this Google IAP subscription challenge you're facing. First, let's touch on that old thread you found—while it's been around for years, the core concern around unexpected state updates in the API is still something to keep an eye on. Google has refined the API since then, but edge cases with reactivated old tokens can still cause headaches, so your question is totally valid.
Key Fields to Watch in the Subscriptions API Response
When you call the subscriptions get endpoint, there are a handful of critical fields in the response that will help you distinguish between a reactivated old token and a brand-new subscription:
orderId: This is your most reliable unique identifier. Every time a user completes a purchase (including re-subscribing after cancellation/expiry), Google generates a neworderId. Even if a user reactivates an old subscription token, if it's a true re-subscription (not just a renewal within an active cycle), theorderIdwill be different from the original one.linkedPurchaseToken: This field links together different purchase tokens for the same user and subscription product. If you get a new token with this field pointing to an old token you've already stored, that's a clear sign the user has re-subscribed, and you should treat the new token as a fresh subscription.startTimeMillis: While the old thread noted issues with this field updating unexpectedly, today it should reflect the initial start time of the current subscription cycle. For reactivated subscriptions, this will be a new timestamp (not just the end of the previous expired cycle), which can help you flag a reactivation.cancelReason&autoRenewing: If you have a stored record of a token whereautoRenewingwasfalse(andcancelReasonwas set, indicating a previous cancellation), but the latest response showsautoRenewingback totruewith no active cancellation reason, that means the user has reactivated the old token.
Step-by-Step Logic to Identify Reactivated Old Tokens
Here's a practical workflow to implement in your system:
- Store complete subscription history for every token: When you first process a purchase token, save all key fields—
orderId,startTimeMillis,expiryTimeMillis,cancelReason,autoRenewing, andlinkedPurchaseToken—in your database. - Compare new API responses to stored data:
- If the current
orderIddoesn't match the stored one for that token: Treat this as a new subscription (even if the token looks familiar—this can happen in rare reactivation cases). - If
autoRenewinghas flipped fromfalsetotrueandcancelReasonis now empty: This means the user reactivated their old canceled subscription. In your system, you should create a new internal subscription record instead of reusing the old one. - Check
linkedPurchaseToken: If a new token'slinkedPurchaseTokenreferences an old token you have on file, mark the old token as inactive and treat the new one as a fresh subscription.
- If the current
- Avoid relying solely on
startTimeMillis: While it can be a clue, stick toorderIdandlinkedPurchaseTokenas your primary identifiers since they're more consistent across edge cases.
Verifying the Old "startTimeMillis" Issue
As for that old thread's concern about startTimeMillis updating unexpectedly: From current API documentation and real-world usage, this issue is much less common now. Google has adjusted the API to ensure startTimeMillis reflects the start of the current active cycle, but it's still wise to cross-reference with other fields (like orderId) to avoid false positives.
内容的提问来源于stack exchange,提问作者libik

