如何 return Instagram 媒体轮播相册中的视频?

How to return video from an Instagram media carousel album?

我正在向 Instagram API 发出请求,以在用户供稿中获取 posts。

https://developers.facebook.com/docs/instagram-api/reference/media/#returnable-fields

似乎有 3 种类型; IMAGEVIDEOCAROUSEL_ALBUM

IMAGE类型中,对象中的media_url键是对图像的link。

VIDEO类型中,对象中的media_url键是mp4视频的link,它还有一个名为thumbnail_url的静态键视频图片。

然而 CAROUSEL_ALBUM 只有一个 media_url 键(像 IMAGE)并且它只是一个图像,即使我知道轮播包含 mp4 视频。

如何获取从 Instagram 返回的 CAROUSEL_ALBUM 类型的视频?

我请求以下字段:

`https://graph.facebook.com/v3.3/${item.id}?access_token=${accessToken}&fields=id,media_type,media_url,thumbnail_url,permalink,caption,timestamp`

这些请求是在 post 个 ID 数组的循环中发出的。我需要进行其他设置吗?

我收到的典型 CAROUSEL_ALBUM 请求如下所示:

{
  "media_type": "CAROUSEL_ALBUM",
  "media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/66441408_2082905628680299_8050667243209299756_n.jpg?_nc_cat=100&_nc_oc=AQk2PElxoGzOzQ_4f-4vANh_Db1Mmra2wkci2aEKbc3vCstLzQeWQxKadbe1ByF8Vec&_nc_ht=scontent.xx&oh=5aa8ac107e1bd5da07b6cb5d760200f6&oe=5DC18C62",
  "permalink": "https://www.instagram.com/p/Bzif-HhAiBk/",
  "caption": "Each video in this carousel stands for a stage in the animation process for our latest experiment, where we animated a 3d model and used it as a basis for the 2d rotoscoping.",
  "timestamp": "2019-07-05T14:50:53+0000",
  "id": "18053365636184706"
}

谢谢

虽然 API return 在 top-level 上有一个轮播类型的视频,但我确实找到了一个 work-around 适合任何人的视频需要它

在旋转木马类型中,应该有一个儿童钥匙。所以你需要在字段的参数中请求它。

在此子字段中使用 sub-fields,您可以获得实际的媒体项(视频)。

例如:

const fields = [
  'caption',
  'children{media_type,media_url,thumbnail_url}',
  'id',
  'media_type',
  'media_url',
  'permalink',
  'thumbnail_url',
  'timestamp'
].join(',')

const request = await fetch(`https://graph.facebook.com/v3.3/${userId}/media?fields=${fields}&access_token=${accessToken}`)

在 JSON 回复的儿童键中,您将看到您的视频。如果您愿意,只需将其用作您的主要媒体即可。

尝试使用 Graph API Explorer 查看您可以使用哪些字段。我无法弄清楚如何 return 宽度和高度,但如果有人知道如何做到这一点。

https://developers.facebook.com/tools/explorer