python - Google Developer API 使用 Python 上传 APK
问题描述
我正在尝试使用 Developer API 将 APK 上传到 Google Play。我有一个主要工作的 Python 脚本,但上传时不断返回“请求‘APK 大小太大’时的 HttpError 403”错误。我们通过网络界面手动上传和发布应用程序没有问题。我在某处缺少设置吗?
这是我当前的脚本:
import argparse
from googleapiclient.discovery import build
import google_auth_httplib2
import httplib2
from oauth2client import client
from google.oauth2 import service_account
from google.auth.transport.requests import Request
import sys, os, socket
def main():
pathname = os.path.dirname(sys.argv[0])
fullpath = os.path.abspath(pathname)
SCOPES = ['https://www.googleapis.com/auth/androidpublisher']
SERVICE_ACCOUNT_FILE = fullpath + '/authorization_data.json' # access keys json file
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
credentials.refresh(Request())
print(credentials.token)
http = httplib2.Http(timeout=300)
http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
service = build('androidpublisher', 'v3', http=http)
package_name = 'com.company.app'
apk_file = 'upload/myapp.apk'
try:
print('creating edit')
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
print('id: ' + edit_id)
print('uploading apk')
apk_response = service.edits().apks().upload(
editId=edit_id,
packageName=package_name,
media_body=apk_file
).execute()
print('Version code %d has been uploaded' % apk_response['versionCode'])
print('committing edit')
commit_request = service.edits().commit(
editId=edit_id,
packageName=package_name
).execute()
print('Edit "%s" has been committed' % commit_request['id'])
except client.AccessTokenRefreshError:
print('The credentials have been revoked or expired, please re-run the application to re-authorize')
if __name__ == '__main__':
main()
解决方案
推荐阅读
- azure - 从 ARM 模板中的 customData (cloud-init) 部分访问 keyvault 中的机密
- javascript - 如何在threejs中添加gltf模型?
- python - 将 pandas 数组的数据类型从 obj 更改为 int
- html - 不同子域的不同社交元预览
- ios - AVCaptureVideoDataOutput 在 iOS 14 中停止传送帧
- c# - 如何在系统路径中找到文件的位置,例如 get-command 或 where?
- perl - Perl 中的 Jenkins 哈希?
- python - 我如何对 docx 生成功能进行单元测试
- python - Akamai Python 登录与耐克
- php - PHP Gmail Api - 删除邮件