如何通过 API 将视频上传到 Pinterest
我正在尝试将视频上传到 Pinterest,因此我按照他们的文档中的说明进行操作 这里
这是我尝试上传的方法
let headers = {
'Authorization': `Bearer ${access_token}`
}
let videoUploadIntentEndpoint = `https://api.pinterest.com/v5/media`;
let videoUploadIntentResponse = await axios.post(videoUploadIntentEndpoint,
{
"media_type": "video"
},
{
headers: headers
}
);
let { media_id, upload_parameters, media_type, upload_url } = videoUploadIntentResponse.data;
if (media_id && upload_url) {
try {
let vidUploadParams = new URLSearchParams();
vidUploadParams.append("file", got.stream(mediaUrl));
let videoUploadResponse = await axios.post(upload_url, vidUploadParams, {
headers: { ...upload_parameters }
});
let vidData = videoUploadResponse.data;
console.log(`Pinterest Video Successful with Data`);
console.log(JSON.stringify(vidData, null, 2));
} catch (vidError) {
console.log(`Pinterest Video Upload Error`);
console.log(vidError);
}
}
,我不断收到的错误是
AccessDenied
没有 AWSAccessKey 提出。AFHHW0M2afafafR9N8afafafafafafa+g5y3qsXqKwta0eN6ND03J7UDEjpk4F1/qbFrfec=
我该如何解决这个问题?
谢谢
I am trying to upload a video to Pinterest, so I followed the instructions in their docs here
Here is how I attempted the upload
let headers = {
'Authorization': `Bearer ${access_token}`
}
let videoUploadIntentEndpoint = `https://api.pinterest.com/v5/media`;
let videoUploadIntentResponse = await axios.post(videoUploadIntentEndpoint,
{
"media_type": "video"
},
{
headers: headers
}
);
let { media_id, upload_parameters, media_type, upload_url } = videoUploadIntentResponse.data;
if (media_id && upload_url) {
try {
let vidUploadParams = new URLSearchParams();
vidUploadParams.append("file", got.stream(mediaUrl));
let videoUploadResponse = await axios.post(upload_url, vidUploadParams, {
headers: { ...upload_parameters }
});
let vidData = videoUploadResponse.data;
console.log(`Pinterest Video Successful with Data`);
console.log(JSON.stringify(vidData, null, 2));
} catch (vidError) {
console.log(`Pinterest Video Upload Error`);
console.log(vidError);
}
}
And the error I keep getting back is
AccessDenied
No AWSAccessKey was
presented.AFHHW0M2afafafR9N8afafafafafafa+g5y3qsXqKwta0eN6ND03J7UDEjpk4F1/qbFrfec=
How can I resolve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文档不是很清楚,但是upload_parameters必须在正文中与文件一起发送,而不是在标头中发送。
“将媒体文件的内容作为请求的文件参数发送,并包含 upload_parameters 中的所有参数”(这很令人困惑,因为 Content-Type 仍然属于标头)
(错误所涉及的 AWSAccessKey 是 x-amz-credentials 字符串的第一部分)
The doc isn't super clear, but the upload_parameters must be sent along the file in the body, not in the headers.
"Send the media file's contents as the request's file parameter and also include all of the parameters from upload_parameters" (this is confusing because Content-Type still belongs in the headers)
(the AWSAccessKey the error is talking about is the first part of the x-amz-credentials string)