1
我想在服務器端驗證來自androidpublisher
API的用戶訂閱。我們有一個月的訂閱我們的應用程序中的產品。我們正在關注的週期如下如何執行身份驗證以驗證Google In App訂閱
- 用戶將獲得產品列表。如果他已經訂閱,他將獲得完整的產品清單。否則,他將只獲得免費產品。
- 當用戶訂閱時,他將從Google購買該收據的收據。該收據將保存在我們的數據庫中。無論何時用戶要求產品列表,該收據都將通過Google API進行驗證。如果它是有效的,他將得到全部結果。否則部分。
Google爲此給出了以下API。
GET https://www.googleapis.com/androidpublisher/v2/applications/ {的packageName} /購買/訂閱/ {subscriptionId} /令牌/ {令牌}
此API需要授權。我想下面的代碼爲這個
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'))
但我得到如下回應
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
請指導我應該怎麼確認收貨之前執行授權。一個重要的觀點,我想驗證服務器端的收據。不是客戶端。因此,用戶將不會看到或點擊任何鏈接來授權此請求。
我有'client_secret','client_id'。 'OAuth2Credentials'至少需要'access_token','client_id','client_secret','refresh_token','token_expiry','token_uri'和'user_agent'。我怎樣才能獲得所有其他參數? –
'access_token = None','token_expiry = datetime.datetime.now()','token_uri ='https:// accounts.google.com/o/oauth2/token'','user_agent'你可以設置任何你想要的,通常是你的應用名稱加上你的應用版本,例如''Hassans App 1.0'(這將被用作請求的'User-Agent'頭部。) –
關於'refresh_token'也許[閱讀此](https://developers.google.com/identity/protocols/ OAuth2用戶)。如果您仍然有問題,請給我更多關於該鏈接中的哪些場景適用於您的用例的詳細信息。 –