0

I'm trying to upload expansion files using the Google Play Publishing API. I've been able to use the edits method to upload apk files with no problem, but attempting a similar solution for obb files has failed. The error I'm getting is:

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

Below is what I have so far up until the failure.

"""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()
Danual
  • 3
  • 2

1 Answers1

0

The api documentation is here. Looking at the error message it has "Unknown file type". According to the API documentation it says:

  • Required query parameters
    • uploadType string The type of upload request to the /upload URI. Acceptable values are:
      • "media" - Simple upload. Upload the media data.
      • "resumable" - Resumable upload. Upload the file in a resumable fashion, using a series of at least two requests.

You don't seem to have set an uploadType parameter in your source code above. Is this the problem?

The documentation also says "Accepted Media MIME types: application/octet-stream" Do you need to set a mime type? The APK it can probably work out from the file extension, but OBB probably has to be set explicitly. The old version of the documentation seemed to mention it talking about a media_mime_type parameter but the current documentation doesn't seem to show it.

Nick Fortescue
  • 13,530
  • 1
  • 31
  • 37
  • It was the second point. It does work out the APK without issue, but can't seem to parse the obb. So all I needed was: mimetypes.add_type('application/octet-stream', '.obb') – Danual Jun 23 '18 at 10:01