500 HttpError when trying to extend googlesamples/android-play-publisher-api to make a subscription revoker

邮差的信 提交于 2019-12-08 11:04:32

问题


So that I can test the subscription functionality of my app, I need to be able to revoke subscriptions. This apparently is not possible just using Google's back end. Instead, it is necessary to use google-play-android-developer-API.

I have downloaded the python android play publisher samples, and gotten them to work. I can for instance run the basic_list_apks.py script to see the list of APKs. This shows that I am authenticating my self correctly etc.

I extended that same basic_list_apks.py to create a minimal subscription_revoker.py script (contents are below). It seems to communicate the correct details to Google. If I make any of the three arguments (packageName,productId, or purchaseToken) wrong, I get an appropriate error from the server. e.g. "Subscription not found for this application." or "The subscription purchase token does not match the subscription ID." etc.

But, when everything seems to be right, all I get is a 500 Server error:

googleapiclient.errors.HttpError: <HttpError 500 when requesting https://www.googleapis.com/androidpublisher/v2/applications/[com.company.app]/purchases/subscriptions/[SKU]/tokens/[purchasetoken]:revoke returned "">

Or written again, with linebreaks to be more legible:

googleapiclient.errors.HttpError: <HttpError 500 when requesting 
https://www.googleapis.com/androidpublisher/v2/
applications/[com.company.app]/purchases/
subscriptions/[SKU]/tokens/[purchasetoken]:revoke returned "">

(Where I have changed the [bracketed] portions of the error to keep my codes private.)

I have googled far and near, and there seem to be others that get mysterious 500 errors from google, but no solutions. Any help would be much appreciated.

Here is my script. To run it, download the samples install the samples mentioned above, and plop the following into a file in the same directory and run it. Thanks for any help anyone can provide.

import sys
from apiclient import sample_tools
from oauth2client import client

## the values you'll need to change
package_name = 'com.yourcompany.yourapp'
product_id = 'the subscription SKU'
purchase_token = 'the purchase token'
## ## ## ##

def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv,
      'androidpublisher',
      'v2',
      __doc__,
      __file__,
      parents=[],
      scope='https://www.googleapis.com/auth/androidpublisher')

  try:
    request = service.purchases().subscriptions().revoke(packageName=package_name,
                                                         subscriptionId=product_id,
                                                         token=purchase_token)
    result = request.execute()
    print(result)

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')

if __name__ == '__main__':
  main(sys.argv)

来源:https://stackoverflow.com/questions/28441359/500-httperror-when-trying-to-extend-googlesamples-android-play-publisher-api-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!