我正在运行一个脚本,该脚本会自动上传捆绑包并在 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()
上传捆绑包时失败,并显示以下错误消息:
googleapiclient.errors.HttpError:
https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.company.app.app/edits/18014957208426515290:commit?alt=json返回“只有状态草稿的版本可以在草稿应用程序上创建。”。详细信息:“只能在草稿应用程序上创建状态为草稿的版本。">
该错误消息没有任何意义,因为事实上我并没有在这个阶段尝试创建一个版本。我只是想上传一个包。所以我只是不知道如何继续......
请注意,我能够手动上传捆绑包并基于它创建内部测试版本。我能够在我的设备上安装它并且它按预期工作,所以我尝试做的事情应该是可能的。
草稿应用程序的首次发布必须是手动的
然后,您必须将
submit_as_draft: true
添加到您的 yaml