安卓发布者: "Track names in request path and request body must match."



我正在使用google api python客户端库将apk上传到google Playstore。直到今天一切都很顺利。我没有修改我的上传脚本,但现在我得到了错误:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/androidpublisher/v3/applications/[packageName]/edits/[editId]/tracks/internal?alt=json returned 
**"Track names in request path and request body must match."**

这是我的上传脚本:

from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client.service_account import ServiceAccountCredentials
import json
import mimetypes
package_name = '...'
keyfile_content = '...'
apk_file = '...'
release_name = '...'
track = 'internal'
mimetypes.add_type("application/octet-stream", ".apk")
mimetypes.add_type("application/octet-stream", ".aab")
keyfile_dict = json.loads(keyfile_content)
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, 'https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
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()
print('Version code %d has been uploaded but not yet committed' % apk_response['versionCode'])
if track:
track_response = service.edits().tracks().update(
editId=edit_id,
track=track,
packageName=package_name,
body={u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
}]}).execute()
print('Track %s is set with releases: %s' % (
track_response['track'], str(track_response['releases'])))
else:
print('No track specified')
commit_request = service.edits().commit(
editId=edit_id, packageName=package_name).execute()
print('Edit "%s" has been committed' % commit_request['id'])

我使用的是谷歌api python客户端1.7.11。

我在网上找不到有关该错误的任何信息。这里有人有主意吗?

更新

感谢@Silvio的回复,我可以通过将曲目添加到请求正文中来重新启动我的脚本:

from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client.service_account import ServiceAccountCredentials
import json
import mimetypes
package_name = '...'
keyfile_content = '...'
apk_file = '...'
release_name = '...'
track = 'internal'
mimetypes.add_type("application/octet-stream", ".apk")
mimetypes.add_type("application/octet-stream", ".aab")
keyfile_dict = json.loads(keyfile_content)
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, 'https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
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()
print('Version code %d has been uploaded but not yet committed' % apk_response['versionCode'])
if track:
track_response = service.edits().tracks().update(
editId=edit_id,
track=track,
packageName=package_name,
body={u'track': track,
u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
}]}).execute()
print('Track %s is set with releases: %s' % (
track_response['track'], str(track_response['releases'])))
else:
print('No track specified')
commit_request = service.edits().commit(
editId=edit_id, packageName=package_name).execute()
print('Edit "%s" has been committed' % commit_request['id'])

还将"track"添加到请求主体中。

例如

body={u'track': track,
u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
...

这对我很有效。你可以在这里查看预期的请求正文结构:

https://developers.google.com/android-publisher/api-ref/edits/tracks#resource

我在用Codemagic发布时遇到了类似的问题Google Play发布失败了"请求路径和请求主体中的轨道名称必须匹配";,看起来谷歌的方面可能出了问题

我也有类似的问题,在这里打开了问题。

https://github.com/googleapis/google-api-python-client/issues/840

如果所有人都能在这个问题上发表意见,那将有所帮助。

我发现自己也处于类似的情况,上周它起了作用,现在它坏了。。。

对于其他使用java版本的Android发布者,我也遇到了同样的错误。

maven工件:谷歌api服务androidpublisher

发布期间出现java错误:

Exception in thread "main" com.netfinca.mobile.publish.apk.PublisherHelperException: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Track names in request path and request body must match.",
"reason" : "badRequest"
} ],
"message" : "Track names in request path and request body must match.",
"status" : "INVALID_ARGUMENT"
}

要解决这个问题,我们必须设置"com.google.api.services.androidpublisher.model.track"对象的track属性

代码如下:

Edit edit = new AndroidPublisher.Builder(...);
Track trackObject = new Track().setTrack(trackValue); // trackValue could be internal, alpha, ...
edit.tracks().update(androidPackage, editId, trackValue, trackObject );

在我的案例中,它缺少了这个:

.setTrack(trackValue);

相关内容

  • 没有找到相关文章

最新更新