【问题标题】:Uploading expansion files using google api client edits method python使用google api客户端编辑方法python上传扩展文件
【发布时间】:2018-06-17 20:45:34
【问题描述】:

我正在尝试使用 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 $4}")], 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()

【问题讨论】:

    标签: android python google-api-python-client google-play-developer-api


    【解决方案1】:

    api documentation is here。查看错误消息,它具有“未知文件类型”。根据 API 文档,它说:

    • 必需的查询参数
      • uploadType string 对 /upload URI 的上传请求的类型。可接受的值为:
        • “媒体” - 简单上传。上传媒体数据。
        • “可恢复”- 可恢复上传。使用一系列至少两个请求以可恢复的方式上传文件。

    您似乎没有在上面的源代码中设置uploadType 参数。是这个问题吗?

    文档还说“接受的媒体 MIME 类型:application/octet-stream” 你需要设置一个mime类型吗?它可能可以从文件扩展名中计算出 APK,但 OBB 可能必须明确设置。 The old version of the documentation 似乎提到它谈论 media_mime_type 参数,但当前文档似乎没有显示它。

    【讨论】:

    • 这是第二点。它确实可以毫无问题地解决 APK,但似乎无法解析 obb。所以我只需要:mimetypes.add_type('application/octet-stream', '.obb')
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 2022-08-16
    相关资源
    最近更新 更多