import requests, redis Redis = redis.Redis() data = requests.post('https://accounts.google.com/o/oauth2/token',{'code':code,'grant_type':'authorization_code','client_id':client_id,'client_secret':client_secret,'redirect_uri':'http://server.ru/callback/'}) jdata = data.json() if 'access_token' in jdata and 'token_type' in jdata and 'expires_in' in jdata: Redis.setex('GooglePayAccess',jdata['access_token'],jdata['expires_in']) Redis.setex('GooglePayType',jdata['token_type'],jdata['expires_in']) if "refresh_token" in jdata: Redis.set('GooglePayRefresh',jdata['refresh_token'])
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://server.ru/callback/&client_id=……………………………………
import requests, redis Redis = redis.Redis() access_token = Redis.get('GooglePayAccess') token_type = Redis.get('GooglePayType') if not access_token or not token_type: refresh_token = Redis.get('GooglePayRefresh') data = requests.post('https://accounts.google.com/o/oauth2/token',{'grant_type':'refresh_token','client_id':client_id,'client_secret':client_secret,'refresh_token':refresh_token}) jdata = data.json() if 'access_token' in jdata and 'token_type' in jdata and 'expires_in' in jdata: access_token = jdata['access_token'] token_type = jdata['token_type'] Redis.setex('GooglePayAccess',access_token,jdata['expires_in']) Redis.set('GooglePayType',token_type,jdata['expires_in']) url = 'https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/products/%s/tokens/%s?key=%s' % (packageName,productId,purchaseToken,api_key) response = requests.get(url,headers={"Authorization":"%s %s" % (token_type,access_token)}) jdata2 = response.json()
Source: https://habr.com/ru/post/240447/
All Articles