无法通过发布者 API 将 APK 上传到 Google Play 开发者
Can't Upload APK to Google Play Developer via Publisher API
我正在使用 nodejs
创建脚本,通过 Publishing API 将我的 APK 上传到 Google Play Developer,但是它失败了。我认为,APK 文件没什么问题,因为它是一个好文件。那么有什么办法可以解决这个问题吗?
我也尝试分段上传,但是return错误(我会尽快附上)
下面是 错误 消息:
Upload successful! Server responded with: {
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "apkInvalidFile",
"message": "Invalid APK file."
}
],
"code": 403,
"message": "Invalid APK file."
}
}
我的源代码
var https = require('https');
var request = require('request');
https.post = require('https-post');
var fs = require('fs');
var tokens = process.argv[2];
var formData = {
my_file: fs.createReadStream('example_file.apk')
}
if (tokens != '')
{
var url_create_listing = 'https://www.googleapis.com/androidpublisher/v2/applications/com.example.apps/edits?access_token='+tokens;
request.post( url_create_listing, function (error, response, body) {
var str_body = JSON.parse (body);
var listing_id = str_body.id;
var url_upload = 'https://www.googleapis.com/upload/androidpublisher/v2/applications/com.example.apps/edits/'+listing_id+'/apks?uploadType=media&access_token='+tokens;
var options = {
url: url_upload,
headers: {
'Content-Type': 'application/vnd.android.package-archive'
}
};
request.post( options, function optionalCallback(err, httpResponse, body)
{
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
}).pipe(fs.createReadStream('example_file.apk'));
});
}
根据https://developers.google.com/games/services/publishing/:
The Google Play games services Publishing API allows you to automate
frequent tasks having to do (...)
您是否在绝对限制下使用 JS & node.js 来完成这项任务?如果没有,您可能会发现这个 Google management-tools 代码示例很有用。
In this repository you can find tools to help you publish, manage, and
test your Play Games services apps
在我看来,安装 Python(并重新使用官方代码)总是更好。
(Google 开发者显然更喜欢 python 来完成这种任务)
我认为您对 NodeJS 流的工作原理有误解。
在上面显示的示例代码中,您试图将 request.post
的结果通过管道传输到 fs.createReadStream
中,这没有任何意义,这就是错误的原因,因为您没有发送任何.apk 文件。相反,它应该像下面这样完成。 (我不确定 androidpublisher api 是如何工作的,我假设你的示例显示了正确的用法。)
var url_create_listing = 'https://www.googleapis.com/androidpublisher/v2/applications/com.example.apps/edits?access_token='+tokens;
request.post( url_create_listing, function (error, response, body) {
var str_body = JSON.parse (body);
var listing_id = str_body.id;
var url_upload = 'https://www.googleapis.com/upload/androidpublisher/v2/applications/com.example.apps/edits/'+listing_id+'/apks?uploadType=media&access_token='+tokens;
// request module is capable of auto detecting the Content-Type header
// based on the file extension.
var options = {
url: url_upload
};
fs.createReadStream('example_file.apk')
.pipe(request.post(options, function optionalCallback(err, httpResponse, body){
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
}));
你看过fastlane.tools了吗? Android 和 iOS.
的发布、上传、截屏、松弛通知等的完整脚本
我正在使用 nodejs
创建脚本,通过 Publishing API 将我的 APK 上传到 Google Play Developer,但是它失败了。我认为,APK 文件没什么问题,因为它是一个好文件。那么有什么办法可以解决这个问题吗?
我也尝试分段上传,但是return错误(我会尽快附上)
下面是 错误 消息:
Upload successful! Server responded with: {
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "apkInvalidFile",
"message": "Invalid APK file."
}
],
"code": 403,
"message": "Invalid APK file."
}
}
我的源代码
var https = require('https');
var request = require('request');
https.post = require('https-post');
var fs = require('fs');
var tokens = process.argv[2];
var formData = {
my_file: fs.createReadStream('example_file.apk')
}
if (tokens != '')
{
var url_create_listing = 'https://www.googleapis.com/androidpublisher/v2/applications/com.example.apps/edits?access_token='+tokens;
request.post( url_create_listing, function (error, response, body) {
var str_body = JSON.parse (body);
var listing_id = str_body.id;
var url_upload = 'https://www.googleapis.com/upload/androidpublisher/v2/applications/com.example.apps/edits/'+listing_id+'/apks?uploadType=media&access_token='+tokens;
var options = {
url: url_upload,
headers: {
'Content-Type': 'application/vnd.android.package-archive'
}
};
request.post( options, function optionalCallback(err, httpResponse, body)
{
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
}).pipe(fs.createReadStream('example_file.apk'));
});
}
根据https://developers.google.com/games/services/publishing/:
The Google Play games services Publishing API allows you to automate frequent tasks having to do (...)
您是否在绝对限制下使用 JS & node.js 来完成这项任务?如果没有,您可能会发现这个 Google management-tools 代码示例很有用。
In this repository you can find tools to help you publish, manage, and test your Play Games services apps
在我看来,安装 Python(并重新使用官方代码)总是更好。
(Google 开发者显然更喜欢 python 来完成这种任务)
我认为您对 NodeJS 流的工作原理有误解。
在上面显示的示例代码中,您试图将 request.post
的结果通过管道传输到 fs.createReadStream
中,这没有任何意义,这就是错误的原因,因为您没有发送任何.apk 文件。相反,它应该像下面这样完成。 (我不确定 androidpublisher api 是如何工作的,我假设你的示例显示了正确的用法。)
var url_create_listing = 'https://www.googleapis.com/androidpublisher/v2/applications/com.example.apps/edits?access_token='+tokens;
request.post( url_create_listing, function (error, response, body) {
var str_body = JSON.parse (body);
var listing_id = str_body.id;
var url_upload = 'https://www.googleapis.com/upload/androidpublisher/v2/applications/com.example.apps/edits/'+listing_id+'/apks?uploadType=media&access_token='+tokens;
// request module is capable of auto detecting the Content-Type header
// based on the file extension.
var options = {
url: url_upload
};
fs.createReadStream('example_file.apk')
.pipe(request.post(options, function optionalCallback(err, httpResponse, body){
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
}));
你看过fastlane.tools了吗? Android 和 iOS.
的发布、上传、截屏、松弛通知等的完整脚本