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

0

1

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)
Monocyclic answered 10/2, 2015 at 20:43 Comment(5)
I wonder if there is something to do with the format of the request? Like perhaps it should be JSON, but it's actually just a GET or POST request or something.Monocyclic
I have also now modified an example from https://github.com/google/google-api-python-client which looks more modern, but unfortunately I still get a 500 error.Monocyclic
I have submitted a bug report to google here: code.google.com/p/android/issues/detail?id=147680Monocyclic
Were you able to solve this, I am stuck with the 500 internal sever error tooWaft
I think that the problem sort of solved itself. I would run the script, occasionally get the error, but then a day or two later, the subscription would be revoked. It was enough for me to do my testing of the subscription purchasing, so I didn't investigate any further. I did notice that I didn't always get the 500 error. I wonder if the 500 error is being raised when the request to revoke the subscription has already been made, but is still pending....?Monocyclic

© 2022 - 2024 — McMap. All rights reserved.