Get videos from a Facebook album using the Graph API

Viewed 106

I can get videos from the user's feed using

me/videos/uploaded

but I want only the videos that belong to a certain album.

I can get photos from the album using

{album-id}/photos

The Facebook documentation does not show any way to get the videos or other media formats that can be uploaded to the same album.

Questions:

  • How can I get a list of videos from the album?
  • Or how can I get the album as a field on the list of videos from the first command?

The goal is to use this list to get reactions for each video, so it would be great if the reactions could also be queried as a field of the video. However, as I have noticed that to get reactions from a photo, I need to query it again using the longhand id {user_id}_{post_id}, I am guessing I could do the same thing once I get the video ids.

1 Answers

There is no way I can find to do it, other than with this 3-step workaround:

  1. Query a list of all videos that the user has uploaded, which is available at the end point me/videos/uploaded.
  2. Use a bot (e.g. Selenium) to check each video at the URL https://www.facebook.com/[user-id]/videos/a.[album-id]/' + [video-id] to see if it actually results in a video, which would indicate it belongs to that album. If there is no video, it was not a valid URL, and that video does not belong to the album. Facebook's robots.txt does not allow bots, but this is not possible using only BeautifulSoup to read the page, as their HTML is JavaScript-rendered.
  3. Query each video to get its reactions, from the endpoint
[user-id]_[video-id]fields=
reactions.type(LOVE).limit(0).summary(total_count).as(love),
reactions.type(WOW).limit(0).summary(total_count).as(wow),
reactions.type(HAHA).limit(0).summary(total_count).as(haha),
reactions.type(LIKE).limit(0).summary(total_count).as(like),
reactions.type(ANGRY).limit(0).summary(total_count).as(angry),
reactions.type(SAD).limit(0).summary(total_count).as(sad)

(Remove all newlines, I only put them in to make it easier to read).

You can also batch request this information for 50 videos at a time. To do this, I used the facebook-sdk package for Python and its get_objects function.

Related