You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于获取应用内购买令牌及从Google Play Console获取令牌用于取消订阅的技术咨询

获取应用内购买令牌及从Google Play Console获取令牌用于取消订阅的技术咨询

Hey there! Great question—there are actually a few reliable ways to get purchase tokens for canceling subscriptions and stopping auto-renewal, both directly through the Play Console and programmatically. Let me break them down for you:

1. Directly Export Subscription Data from Google Play Console

This is the simplest method for bulk retrieval, no coding required:

  • Log into your Google Play Console and navigate to your target app.
  • Go to Monetization > Subscriptions (or Orders > All orders if you need individual transaction tokens).
  • Look for the Export button at the top of the page. Choose your desired time range and export format (CSV or JSON).
  • The exported file will include the purchaseToken field for every subscription/order—this is exactly the token you need to cancel auto-renewal.

2. Use the Google Play Developer API for Automated/Bulk Access

If you need to automate this process or integrate it into your backend systems, the API is the way to go:

  • First, enable the Google Play Developer API in your Play Console’s API access section, and create a service account with the appropriate credentials (make sure it has permissions like "View app data" or "Edit app data").
  • Use the purchases.subscriptions.list (or purchases.subscriptionsv2.list for newer subscription models) endpoint. You’ll need to provide your app’s package name and the user’s Google ID (if you have it stored in your database).
  • Here’s a quick Python example of how to call the API:
    from googleapiclient.discovery import build
    from google.oauth2 import service_account
    
    # Load your service account credentials
    credentials = service_account.Credentials.from_service_account_file(
        'path/to/your/credentials.json',
        scopes=['https://www.googleapis.com/auth/androidpublisher']
    )
    
    # Initialize the Android Publisher service
    service = build('androidpublisher', 'v3', credentials=credentials)
    
    # Fetch subscriptions for a specific user
    subscriptions_response = service.purchases().subscriptions().list(
        packageName='com.your.app.package',
        userId='user_google_account_id'
    ).execute()
    
    # Extract purchase tokens from the response
    purchase_tokens = [sub['purchaseToken'] for sub in subscriptions_response.get('subscriptions', [])]
    
  • Note: To get tokens for all users, you’ll need to pair this with your own user database (since the API requires a user ID to query their subscriptions).

3. Retrieve Tokens In-App for Individual Users

If you’re handling a single user’s cancellation request, you can fetch their token directly from your app using the Google Play Billing Library:

  • Integrate the latest Google Play Billing Library (v5+ is recommended) into your app.
  • Use the queryPurchasesAsync method to fetch the user’s active subscriptions. Each returned Purchase object has a getPurchaseToken() method that gives you the token.
  • You can then send this token to your backend to process the cancellation, or call the cancellation API directly from your app (though backend processing is safer).

Best Practices to Keep in Mind

  • Store tokens in your backend: Whenever a user subscribes, save their purchaseToken to your database. This eliminates the need to fetch it from Play Console every time you need to manage their subscription.
  • Batch operations efficiently: For bulk cancellations, use the Play Console export or API batch requests instead of manual lookup—it saves time and reduces errors.
  • Validate permissions: When using the API, double-check that your service account has the correct permissions to access subscription data and modify subscriptions.
  • Confirm cancellation: After using the token to call the purchases.subscriptions.cancel endpoint, verify that the subscription’s auto-renewal status is set to false to ensure the operation worked.

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 12:34:31