import httplib2 from googleapiclient.discovery import build from oauth2client.service_account import ServiceAccountCredentials from oauth2client.client import AccessTokenRefreshError # Может принимать значения "alpha", "beta", "production" или "rollout" TRACK = "alpha" package_name = "your.package.name" key_filename = "your_key_filename.json" scope = ['https://www.googleapis.com/auth/androidpublisher'] def build_androidpublisher_service(): creds = ServiceAccountCredentials.from_json_keyfile_name(key_filename, scope) http_auth = creds.authorize(http=httplib2.Http()) return build('androidpublisher', 'v3', http=http_auth) def generate_edit(service): edit_request = service.edits().insert(body={}, packageName=package_name) result = edit_request.execute() return result['id'] def main(): try: service = build_androidpublisher_service() edit_id = generate_edit(service) # Загружаем apk на сервера google apk_response = service.edits().apks().upload( editId=edit_id, packageName=package_name, media_body=apk_file ).execute() # Выводим код версии, как подтверждение успешной загрузки print("Version code {} has been uploaded".format(apk_response['versionCode'])) # Теперь надо установить Track, чтобы apk задеплоились в правильную ветку track_response = service.edits().tracks().update( editId=edit_id, packageName=package_name, track=TRACK, body={"versionCodes": [apk_response['versionCode']]} ).execute() # Выводим сообщение об успешной установке Track'а для VC print("Track {} is set for version code(s) {}".format( track_response['track'], str(track_response['versionCodes']) )) # В конце надо закрепить edit commit_request = service.edits().commit(editId=edit_id, packageName=package_name).execute() # И вывести сообщение об этом print("Edit \"{}\" has been committed".format(commit_request['id'])) except AccessTokenRefreshError: print("The credentials have been revoked or expired, re-run the app to re-authorize") if __name__ == '__main__': main()