方框节点 API 可以获取文件夹信息但无法创建文件夹
Box node API Can get folder info but cannot create folder
我确定我在身份验证周期中做错了什么,但我一直收到 500 条消息,而且消息非常模糊。
所以,我正在从我的节点服务器调用 box。首先我创建一个客户端:
const sdk = new BoxSDK({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
appAuth: {
keyID: process.env.PUBLIC_KEY_ID,
privateKey: fs.readFileSync(path.resolve(__dirname, process.env.PRIVATE_KEY_PATH)),
passphrase: process.env.PRIVATE_KEY_PASSPHRASE,
},
});
app.use((req, res, next) => {
req.sdk = sdk.getAppAuthClient('user', process.env.BOX_USER_ID);
next();
});
创建客户端后,我会触发一个请求:
export function yearEnd(req, res) {
req.sdk.folders.create({
name: 'test',
parent: {
id: '0',
},
}, (e, r) => {
if (e) {
return res.send(e);
}
return res.status(201).send(r);
});
}
我得到的回复是:
{
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
},
"response": {
"statusCode": 500,
"body": {
"type": "error",
"status": 500,
"code": "internal_server_error",
"help_url": "http://developers.box.com/docs/#errors",
"message": "Internal Server Error",
"request_id": "29462704457e0f3876ee08"
},
"headers": {
"server": "ATS",
"date": "Tue, 20 Sep 2016 08:29:59 GMT",
"content-type": "application/json",
"content-length": "188",
"cache-control": "no-cache, no-store",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"vary": "Accept-Encoding",
"age": "0",
"connection": "keep-alive"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
}
},
"statusCode": 500,
"maxRetriesExceeded": true
}
谁能告诉我我做错了什么??
所以,文档和方法签名不匹配。我不得不进入包裹并手动检查代码。要创建,它是:
req.sdk.folders.create(<parent_id>, <folderName>, (e, r) => {...});
我确定我在身份验证周期中做错了什么,但我一直收到 500 条消息,而且消息非常模糊。
所以,我正在从我的节点服务器调用 box。首先我创建一个客户端:
const sdk = new BoxSDK({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
appAuth: {
keyID: process.env.PUBLIC_KEY_ID,
privateKey: fs.readFileSync(path.resolve(__dirname, process.env.PRIVATE_KEY_PATH)),
passphrase: process.env.PRIVATE_KEY_PASSPHRASE,
},
});
app.use((req, res, next) => {
req.sdk = sdk.getAppAuthClient('user', process.env.BOX_USER_ID);
next();
});
创建客户端后,我会触发一个请求:
export function yearEnd(req, res) {
req.sdk.folders.create({
name: 'test',
parent: {
id: '0',
},
}, (e, r) => {
if (e) {
return res.send(e);
}
return res.status(201).send(r);
});
}
我得到的回复是:
{
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
},
"response": {
"statusCode": 500,
"body": {
"type": "error",
"status": 500,
"code": "internal_server_error",
"help_url": "http://developers.box.com/docs/#errors",
"message": "Internal Server Error",
"request_id": "29462704457e0f3876ee08"
},
"headers": {
"server": "ATS",
"date": "Tue, 20 Sep 2016 08:29:59 GMT",
"content-type": "application/json",
"content-length": "188",
"cache-control": "no-cache, no-store",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"vary": "Accept-Encoding",
"age": "0",
"connection": "keep-alive"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
}
},
"statusCode": 500,
"maxRetriesExceeded": true
}
谁能告诉我我做错了什么??
所以,文档和方法签名不匹配。我不得不进入包裹并手动检查代码。要创建,它是:
req.sdk.folders.create(<parent_id>, <folderName>, (e, r) => {...});