首页 > 解决方案 > 将视频上传到 Instagram 企业帐户总是返回“媒体 ID 不可用”错误消息

问题描述

我需要将照片或视频发布到经过身份验证的 Instagram 企业帐户。

我已获得 Instagram 商业帐户的访问令牌,现在我希望将视频上传到该帐户,但我不断收到此错误消息

媒体 ID 不可用

我按照说明从此处的文档上传视频或照片https://developers.facebook.com/docs/instagram-api/guides/content-publishing/

请注意,以下代码在上传照片时效果很好,但在上传视频时总是失败。

这是我遵循他们的文档后的代码:

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);
}

请注意,mediaUrl以上来自远程网址,例如https://somewhere.com/video.mp4

再一次,用上面的代码上传一张照片是完美的,但当它是视频时,它永远不会起作用。我不断收到以下完整错误消息:

OAuth "Facebook Platform" "invalid_request" "媒体 ID 不可用

经过仔细观察,我注意到确实creation_id是为视频生成的,坦率地说,我仍然收到上述错误消息很奇怪。

请问,我做错了什么?

我感谢解决此问题的任何建议。

标签: node.jsfacebookfacebook-graph-apiinstagraminstagram-api

解决方案


所以,这就是问题所在。当您将视频上传到 /media 端点时,视频需要一些时间来处理,并且在此期间视频将无法发布,因此 /media_publish 端点返回“Media Id not available”的原因。解决方案是检查容器的发布状态:GET: /{ig-container-id}?fields=status_code. 只有当 status_code 为“FINISHED”时,容器才可用于发布。检查下面的链接以获取更多详细信息

IG 内容发布问题排查


推荐阅读