使用 google api 客户端编辑方法上传扩展文件 python
Uploading expansion files using google api client edits method python
我正在尝试使用 Google Play Publishing API 上传扩展文件。我已经能够使用 edits 方法毫无问题地上传 apk 文件,但是对 obb 文件尝试类似的解决方案失败了。我得到的错误是:
Traceback (most recent call last): File "local_guppy_script.py", line 114, in <module> main()
File "local_guppy_script.py", line 86, in main media_body=obb_file).execute()
File "/Users/danual.allen/projects/guppy_script/guppy/lib/python3.6/site-packages/googleapiclient/discovery.py", line 805, in method
raise UnknownFileType(media_filename)
googleapiclient.errors.UnknownFileType: /Users/danual.allen/Desktop/obb_test_files/main.6.com.anglerfishgames.obbmcotestgoog.obb
以下是我在失败之前所拥有的。
"""Uploads an apk to the internal test track."""
import argparse
import subprocess
import os
from googleapiclient.discovery import build
import httplib2
from oauth2client.service_account import ServiceAccountCredentials
from oauth2client import client
TRACK = 'internal' # Can be 'alpha', beta', 'production' or 'rollout'
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('package_name',
help='The package name. Example: com.android.sample')
argparser.add_argument('apk_file',
nargs='?',
default='test.apk',
help='The path to the APK file to upload.')
argparser.add_argument('obb_file',
help='The path to the obb file to upload.')
def main():
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'JSON_FILE',
scopes='https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
# Process flags and read their values.
flags = argparser.parse_args()
package_name = flags.package_name
apk_file = flags.apk_file
obb_file = os.path.abspath(flags.obb_file)
current_version_code = subprocess.check_output(['''aapt dump badging {} | awk -v FS="'" '/package: name=/{}' | tr -d '\n' '''.format(os.path.abspath(apk_file), "{print }")], shell=True)
try:
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
apk_response = service.edits().apks().upload(
editId=edit_id,
packageName=package_name,
media_body=apk_file).execute()
obb_response = service.edits().expansionfiles().upload(
apkVersionCode=current_version_code,
editId=edit_id,
expansionFileType="main",
packageName=package_name,
media_body=obb_file).execute()
api documentation is here。查看错误消息它有 "Unknown file type"。根据 API 文档,它说:
- 必需的查询参数
- uploadType string 对 /upload URI 的上传请求类型。可接受的值是:
- "media" - 简单上传。上传媒体数据。
- "resumable" - 可续传。使用一系列至少两个请求以可恢复的方式上传文件。
您似乎没有在上面的源代码中设置 uploadType 参数。是这个问题吗?
文档还说 "Accepted Media MIME types: application/octet-stream
"
您需要设置 MIME 类型吗? APK 可能可以从文件扩展名中计算出来,但 OBB 可能必须明确设置。 The old version of the documentation 似乎提到它谈论 media_mime_type 参数,但当前文档似乎没有显示它。
我正在尝试使用 Google Play Publishing API 上传扩展文件。我已经能够使用 edits 方法毫无问题地上传 apk 文件,但是对 obb 文件尝试类似的解决方案失败了。我得到的错误是:
Traceback (most recent call last): File "local_guppy_script.py", line 114, in <module> main()
File "local_guppy_script.py", line 86, in main media_body=obb_file).execute()
File "/Users/danual.allen/projects/guppy_script/guppy/lib/python3.6/site-packages/googleapiclient/discovery.py", line 805, in method
raise UnknownFileType(media_filename)
googleapiclient.errors.UnknownFileType: /Users/danual.allen/Desktop/obb_test_files/main.6.com.anglerfishgames.obbmcotestgoog.obb
以下是我在失败之前所拥有的。
"""Uploads an apk to the internal test track."""
import argparse
import subprocess
import os
from googleapiclient.discovery import build
import httplib2
from oauth2client.service_account import ServiceAccountCredentials
from oauth2client import client
TRACK = 'internal' # Can be 'alpha', beta', 'production' or 'rollout'
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('package_name',
help='The package name. Example: com.android.sample')
argparser.add_argument('apk_file',
nargs='?',
default='test.apk',
help='The path to the APK file to upload.')
argparser.add_argument('obb_file',
help='The path to the obb file to upload.')
def main():
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'JSON_FILE',
scopes='https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
# Process flags and read their values.
flags = argparser.parse_args()
package_name = flags.package_name
apk_file = flags.apk_file
obb_file = os.path.abspath(flags.obb_file)
current_version_code = subprocess.check_output(['''aapt dump badging {} | awk -v FS="'" '/package: name=/{}' | tr -d '\n' '''.format(os.path.abspath(apk_file), "{print }")], shell=True)
try:
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
apk_response = service.edits().apks().upload(
editId=edit_id,
packageName=package_name,
media_body=apk_file).execute()
obb_response = service.edits().expansionfiles().upload(
apkVersionCode=current_version_code,
editId=edit_id,
expansionFileType="main",
packageName=package_name,
media_body=obb_file).execute()
api documentation is here。查看错误消息它有 "Unknown file type"。根据 API 文档,它说:
- 必需的查询参数
- uploadType string 对 /upload URI 的上传请求类型。可接受的值是:
- "media" - 简单上传。上传媒体数据。
- "resumable" - 可续传。使用一系列至少两个请求以可恢复的方式上传文件。
- uploadType string 对 /upload URI 的上传请求类型。可接受的值是:
您似乎没有在上面的源代码中设置 uploadType 参数。是这个问题吗?
文档还说 "Accepted Media MIME types: application/octet-stream
"
您需要设置 MIME 类型吗? APK 可能可以从文件扩展名中计算出来,但 OBB 可能必须明确设置。 The old version of the documentation 似乎提到它谈论 media_mime_type 参数,但当前文档似乎没有显示它。