I want to validate user subscription from androidpublisher API in server side. We have one month subscription for a product in our App. The cycle which we are following is below
- User will get product list. If he has subscribed, he will get full list of products. Otherwise he will get only free products.
- When user will subscribe, he will get a receipt from google for that purchase. That receipt will be saved in our database. Whenever user will demand list of products, that receipt will be validated from Google API. If it is valid, he will get full result. Otherwise partial.
Google has given below API for this purpose.
GET https://www.googleapis.com/androidpublisher/v2/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}
This Api requires authorization. I tried below code for this
receipt_json = json.loads(subscription_object.receipt)
service = build(serviceName='androidpublisher', version='v2', developerKey='key')
response = service.purchases().subscriptions().get(
packageName=receipt_json.get('packageName'),
subscriptionId=receipt_json.get('productId'),
token=receipt_json.get('purchaseToken'))
But I got below response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Please guide me how should I perform authorization before validating receipt. One importent point, I want to validate receipt in server side. Not client side. So user will not see or click any link in order to authorize this request.