android 无法使用Play API上传应用包

9rnv2umw  于 5个月前  发布在  Android
关注(0)|答案(1)|浏览(103)

bounty将在3天后过期。回答此问题可获得+50声望奖励。Julien Debache希望引起更多关注此问题。

我运行了一个脚本,它会自动上传一个捆绑包,并在Play商店中创建一个内部测试版本。这个脚本非常适合非草稿应用程序。但是,我想为我正在开发的新应用程序设置这个脚本,我目前无法将其置于非草稿状态(我没有任何版本准备生产),但我仍然希望能够给予它给一些内部测试人员,并更新他们的版本,因为我在应用程序上的工作。匿名:

import os
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

# Get the app ID from the environment.
app_id = "com.company.app.app"
print(f"App ID set to {app_id}.")

# Get the APK file path from the environment.
aab_file_path = "/output/com.company.app.app-Signed.aab"
print(f"Path to bundle set to {aab_file_path}.")

# Get the service account JSON file path from the environment.
service_account_file_path = "/service-account-key.json"
print(f"Path to service account key set to {service_account_file_path}.")

# Create the service account credentials object.
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    service_account_file_path, ["https://www.googleapis.com/auth/androidpublisher"]
)

# Create the API client object.
service = build("androidpublisher", "v3", credentials=credentials)

# Get an edit ID.
print(f"Creating an edit for bundle upload...")
request = service.edits().insert(packageName=app_id)
response = request.execute()
editId = response['id']
print(f"Edit ID for bundle upload is {editId}.")

with open(aab_file_path, "rb") as f:
  request = service.edits().bundles().upload(
      packageName=app_id,
      editId=editId,
      media_body=aab_file_path,
      media_mime_type="application/octet-stream",
  )
  print(f"Creating edit for bundle upload...")
  response = request.execute()
  versionCode = response.get("versionCode")
  print(f"Bundle version code is {versionCode}.")
  print(f"Commiting bundle upload edit...")
  request = service.edits().commit(editId=editId, packageName=app_id)
  response = request.execute()
  print(f"Bundle upload successfull.")

request = service.edits().insert(packageName=app_id)
response = request.execute()
editId = response['id']
release = {
  "versionCodes": [
    versionCode
  ],
  "releaseNotes": [
    {
      "language": "en_GB",
      "text": "Minor Improvements"
    }
  ],
  "status": "draft",
}
track = {
  "track": "internal",
  "releases": [
    release
  ]
}
request = service.edits().tracks().update(packageName=app_id, editId=editId, track="internal", body=track)
response = request.execute()
request = service.edits().commit(packageName=app_id, editId=editId)
response = request.execute()

字符串
上传bundle时失败,并显示以下错误消息:
googleapiclient.errors.HttpError:<请求https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.company.app.app/edits/18014957208426515290:commit?alt=json时出现HttpError 400返回“只能在草稿应用上创建具有草稿状态的版本"。详细信息:“只能在草稿应用上创建具有草稿状态的版本">
这个错误消息没有任何意义,因为我并没有,事实上,试图在这个阶段创建一个版本。我只是试图上传一个捆绑包。所以我只是不知道如何继续.
请注意,我可以手动上传一个bundle,并基于它创建一个内部测试版本。我可以将它安装在我的设备上,它按预期工作,所以我尝试做的应该是可能的。

3qpi33ja

3qpi33ja1#

第一次发布的草案应用程序必须是手动的
然后,你必须添加submit_as_draft: true到你的yaml

相关问题