如何通过 API 将视频上传到 Pinterest

发布于 2025-01-09 22:58:47 字数 1373 浏览 0 评论 0原文

我正在尝试将视频上传到 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

AccessDeniedNo AWSAccessKey was
presented.AFHHW0M2afafafR9N8afafafafafafa+g5y3qsXqKwta0eN6ND03J7UDEjpk4F1/qbFrfec=

How can I resolve this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老旧海报 2025-01-16 22:58:47

该文档不是很清楚,但是upload_parameters必须在正文中与文件一起发送,而不是在标头中发送。
“将媒体文件的内容作为请求的文件参数发送,并包含 upload_parameters 中的所有参数”(这很令人困惑,因为 Content-Type 仍然属于标头)

(错误所涉及的 AWSAccessKeyx-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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文