Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用google api客户端编辑方法python上载扩展文件_Android_Python_Google Api Python Client_Google Play Developer Api - Fatal编程技术网

Android 使用google api客户端编辑方法python上载扩展文件

Android 使用google api客户端编辑方法python上载扩展文件,android,python,google-api-python-client,google-play-developer-api,Android,Python,Google Api Python Client,Google Play Developer Api,我正在尝试使用Google Play发布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_

我正在尝试使用Google Play发布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
这个。查看错误消息,它具有“未知文件类型”。根据API文档,它说:

  • 必需的查询参数
    • uploadType字符串/upload URI的上载请求类型。可接受值为:
      • “媒体”-简单的上传。上传媒体数据
      • “可恢复”-可恢复上传。使用一系列至少两个请求,以可恢复的方式上载文件
您似乎没有在上面的源代码中设置uploadType参数。这就是问题所在吗

文档中还提到“可接受的媒体MIME类型:
应用程序/octet流

您需要设置mime类型吗?APK可能是通过文件扩展名计算出来的,但OBB可能必须显式设置。似乎提到了媒体mime类型参数,但当前文档似乎没有显示它。

这是第二点。它确实可以毫无问题地解决APK问题,但似乎无法解析obb。所以我只需要:mimetypes.add_type('application/octet stream','.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()