简体   繁体   English

上传到 Instagram 企业帐户的视频总是返回“媒体 ID 不可用”错误消息

[英]Video upload to Instagram Business Account always returns "Media ID is not available" error message

I need to publish either a photo or video to an authenticated Instagram Business Account.我需要将照片或视频发布到经过身份验证的 Instagram 企业帐户。

I have gotten the access token to the Instagram Business Account and now I wish to upload a video to that account but I keep getting back this error message我已经获得了 Instagram 商业帐户的访问令牌,现在我想将视频上传到该帐户,但我一直收到此错误消息

Media ID is not available媒体 ID 不可用

I followed the instructions to upload either a video or photo from the docs here https://developers.facebook.com/docs/instagram-api/guides/content-publishing/我按照说明从此处的文档上传视频或照片https://developers.facebook.com/docs/instagram-api/guides/content-publishing/

Please note that the below code works perfectly well at uploading Photos but always fails when it's video.请注意,下面的代码在上传照片时效果很好,但在上传视频时总是失败。

Here is my code after following their documentation:这是遵循他们的文档后的代码:

let mediaContainerUrl = `https://graph.facebook.com/${igUserId}/media`;
let containerParams = new URLSearchParams();
if (isPhoto) {
    containerParams.append('image_url', mediaUrl);
} else {
    containerParams.append('video_url', mediaUrl);
    containerParams.append('media_type', 'VIDEO');
}
containerParams.append('caption', caption);
containerParams.append('access_token', accessToken);
try {
    let mediaContainerResponse = await axios.post(mediaContainerUrl, containerParams);
    let { id } = mediaContainerResponse.data;

    // id above is supposed to be the creation_id needed for the next step below:

    // I can confirm that the id for the created media container was actually returned. 
    // So, it's weird for me to keep getting the Media ID not available error message.

    let mediaPublishResponse = await axios.post(`https://graph.facebook.com/${igUserId}/media_publish?creation_id=${id}&access_token=${access_token}`);
    let mediaPublishResponseData = mediaPublishResponse.data;
    let publishedMediaId = mediaPublishResponseData.id;
    console.log(`File uploaded to Instagram!`);

} catch (e) {
    console.log(`Instagram file upload failed miserably`);
    console.log(e);
}

Please note that mediaUrl above is coming from a remote url eg https://somewhere.com/video.mp4请注意,上面的mediaUrl来自远程 url,例如https://somewhere.com/video.mp4

Once again, uploading a Photo with the above code is working perfectly but never works when it's video.再一次,使用上面的代码上传照片可以完美地工作,但在视频时却无法正常工作。 I keep getting the following full error message:我不断收到以下完整错误消息:

OAuth "Facebook Platform" "invalid_request" "Media ID is not available OAuth "Facebook 平台" "invalid_request" "媒体 ID 不可用

After careful observation I noticed that indeed the creation_id was generated for the video, so quite frankly, it's weird that I am still getting the above error message.经过仔细观察,我发现确实为视频生成了creation_id ,所以坦率地说,我仍然收到上述错误消息,这很奇怪。

Please, what could I be doing wrong?请问,我做错了什么?

I'm thankful to any suggestions in resolving this.我感谢解决此问题的任何建议。

So, here is what the problem is.所以,这就是问题所在。 When you upload a video to the /media endpoint, the video takes some time to be processed, and the video will not be available for publishing during this time, hence the reason the /media_publish endpoint is returning "Media Id not available".当您将视频上传到 /media 端点时,视频需要一些时间来处理,并且在此期间视频将无法发布,因此 /media_publish 端点返回“媒体 ID 不可用”的原因。 The solution to this would be to check for the container's publishing status: GET: /{ig-container-id}?fields=status_code .解决方案是检查容器的发布状态: GET: /{ig-container-id}?fields=status_code Only when the status_code is "FINISHED" is the container available for publishing.只有当 status_code 为“FINISHED”时,容器才可用于发布。 Check the link below for more details查看下面的链接了解更多详情

IG content publish troubleshooting IG 内容发布故障排除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM