【发布时间】:2021-05-23 09:18:38
【问题描述】:
我正在尝试使用 Node.js 上传带有 android publisher api of google 的捆绑包:
const https = require('https');
const fs = require('fs');
const bundle_path = ...
const package = ...
const editID = ...
const token = ...
const options = {
hostname: 'androidpublisher.googleapis.com',
port: 443,
path: `/androidpublisher/v3/applications/${package}/edits/${editID}/bundles/`,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/octet-stream',
'Content-Length': fs.statSync(bundle_path).size
}
};
https.request(options, res => {
let chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => console.log(Buffer.concat(chunks).toString()));
})
.end(fs.readFileSync(bundle_path));
但它返回一个错误
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unexpected token.\nPK\u0003\u0004\u0014\u0000\u0000\u0000\b\u0000\u000eOTR%\n^",
"status": "INVALID_ARGUMENT"
}
}
我找不到我的 Node.js 代码中缺少的内容。
【问题讨论】:
-
你从哪里得到的令牌?
-
好的,代码在哪里?你跟着这个对吗? developers.google.com/android-publisher/…
-
错误的链接我用好的链接更新了
标签: node.js rest https google-api androidpublisher