使用 Graph 从 Facebook 事件中获取照片和视频 API

Fetching photos and videos from a Facebook event using the Graph API

我正在尝试使用 Facebook 图表从 Facebook 活动中获取所有照片和视频 API。

目前我正在使用 /{event-id}/feed 端点,在此处描述 https://developers.facebook.com/docs/graph-api/reference/v2.6/event/feed

通过指定我想要的字段,我可以从这个端点获得几乎我需要的一切,但是我无法URL完整地看到视频解析度。我可以通过再次调用 API 轻松获取它们,但如果可能的话,我想避免对所有视频再次调用 API。

请注意 /{event-id}/feed 端点 returns 一个 Post objects 的数组,这是我使用 fields 查询参数查询的内容。

https://developers.facebook.com/docs/graph-api/reference/v2.6/post

这是我在调用 /{event-id}/feed 端点时指定的字段

https://graph.facebook.com/v2.6/{event-id}/feed?fields=attachments,id,created_time,caption,from,name,message,message_tags,source,type,status_type,properties,object_id,picture&access_token={access-token}

attachments 字段为我提供了高分辨率视频的图像 URL 以及视频本身的 ID。这意味着我需要进行额外的 API 调用才能使用 /{video-id} 端点获得高分辨率的视频 URL。

"attachments": {
        "data": [
           {
              "media": {
                 "image": {
                    "height": 405,
                    "src": "https://scontent.xx.fbcdn.net/v/t15.0-10/s720x720/13433040_10154318390596912_1315696369_n.jpg?oh=46987fa671df2deca3ce935a68e1ff30&oe=58008D60",
                    "width": 720
                 }
              },
              "target": {
                 "id": "10154318389716912",
                 "url": "https://www.facebook.com/{username-removed}/videos/10154318389716912/"
              },
              "type": "video_autoplay",
              "url": "https://www.facebook.com/{username-removed}/videos/10154318389716912/"
           }
        ]
     }

source 字段给我 link 低分辨率视频。

"source": "https://video.xx.fbcdn.net/v/t42.1790-2/13543016_152852391800500_1248221173_n.mp4?efg=eyJybHIiOjMxMywicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0\u00253D&rl=313&vabr=174&oh=f0f42856741b81030ea529fe89f80834&oe=5771B45B"

object_id 字段为我提供了视频 ID。

properties 字段给出了视频的长度。

所以我运气不好。我想知道是否可以进行一些嵌套调用来给我高分辨率视频的 URL,或者我是否可以使用 returns 302 重定向到视频的视频 ID 调用某些端点.我可以修改源代码的参数吗URL?

非常感谢任何帮助。谢谢!

"...I'm wondering if it's possible to make some nested call that would give me the URL of the high resolution video..."

解决方法 :

要一次完成所有 API 调用,您可以尝试使用图 API 进行 批量请求

请参阅文档和示例:Facebook API - Making Multiple Requests

引自 Docs :

" ... Batching allows you to pass instructions for several operations in a single HTTP request. You can also specify dependencies between related operations (described in a section below). Facebook will process each of your independent operations in parallel and will process your dependent operations sequentially. Once all operations have been completed, a consolidated response will be passed back to you and the HTTP connection will be closed."

如你所见,就是发起多个请求,并在它们之间创建依赖关系。
因此,当您获得 video_id 时,您可以立即以您想要的分辨率请求视频。