node.js - 将视频上传到 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
是为视频生成的,坦率地说,我仍然收到上述错误消息很奇怪。
请问,我做错了什么?
我感谢解决此问题的任何建议。
解决方案
所以,这就是问题所在。当您将视频上传到 /media 端点时,视频需要一些时间来处理,并且在此期间视频将无法发布,因此 /media_publish 端点返回“Media Id not available”的原因。解决方案是检查容器的发布状态:GET: /{ig-container-id}?fields=status_code
. 只有当 status_code 为“FINISHED”时,容器才可用于发布。检查下面的链接以获取更多详细信息
推荐阅读
- java - LocalDateTime :将字符串转换为 HH:mm:ss
- c++ - 循环计数器输入后程序挂起 - 没有无限循环或段错误
- angularjs - ng-click 不会调用 angularJs 控制器中的方法
- react-native - React-Native Expo:如何保持应用程序标签栏显示在应用程序内浏览器上?
- r - 使用 dplyr 的 select 和 Everything() 重新排列变量
- c# - UWP NavigationView 未与标题栏后退按钮对齐
- php - 将 SQL 数据库中的约束提取到 PHP 中的 JSON
- python-3.x - 使用 xarray 更改坐标系以进行切片操作
- php - 使用变量键名访问 php 中的 $_GET / $_POST 数据
- python - 映射一个字符串获取每个单词的长度并附加到一个带有条件的新单词