def login(self): if self.loggedIn: return {'status': 'SUCCESS', 'securityCheck': False, 'message': 'OK'} try: if not self.has_credentials(): raise LoginError("missing credentials") self.service.login(self._email, self._passwd, self._gsfId, self._token) self.loggedIn = True return {'status': 'SUCCESS', 'securityCheck': False, 'message': 'OK'} except LoginError as e: print('LoginError: {0}'.format(e)) self.loggedIn = False return {'status': 'ERROR', 'securityCheck': False, 'message': 'Wrong credentials'} except SecurityCheckError as e: print('SecurityCheckError: {0}'.format(e)) self.loggedIn = False return {'status': 'ERROR', 'securityCheck': True, 'message': 'Need security check'} except RequestError as e: # probably tokens are invalid, so it is better to # invalidate them print('RequestError: {0}'.format(e)) self.loggedIn = False return {'status': 'ERROR', 'securityCheck': False, 'message': 'Request error, probably invalid token'}
def download(self, packageName, versionCode=None, offerType=1, expansion_files=False): """ 避免 Unexpected end-group tag. 错误 参考:https://github.com/NoMore201/googleplay-api/issues/132 """ if self.authSubToken is None: raise LoginError("You need to login before executing any request") if versionCode is None: # pick up latest version appDetails = self.details(packageName).get('details').get( 'appDetails') versionCode = appDetails.get('versionCode') headers = self.getHeaders() params = { 'ot': str(offerType), 'doc': packageName, 'vc': str(versionCode) } response = requests.post(PURCHASE_URL, headers=headers, params=params, verify=ssl_verify, timeout=60, proxies=self.proxies_config) response = googleplay_pb2.ResponseWrapper.FromString(response.content) if response.commands.displayErrorMessage != "": raise RequestError(response.commands.displayErrorMessage) else: dlToken = response.payload.buyResponse.downloadToken return self.delivery(packageName, versionCode, offerType, dlToken, expansion_files=expansion_files)
def login(self): if self.loggedIn: return {'status': 'SUCCESS', 'message': 'OK'} try: if self._email is None or self._passwd is None: raise LoginError("either username or password is null") self.service.login(self._email, self._passwd, None, None) self.loggedIn = True return {'status': 'SUCCESS', 'message': 'OK'} except LoginError as e: print('LoginError: {0}'.format(e)) self.loggedIn = False return {'status': 'ERROR', 'message': 'Wrong credentials'} except RequestError as e: # probably tokens are invalid, so it is better to # invalidate them print('RequestError: {0}'.format(e)) self.loggedIn = False return { 'status': 'ERROR', 'message': 'Request error, probably invalid token' }