MediaPost
A Facebook media post — One Photo or Video that is its own post, with its own comments and reactions.
MediaPost can be created with:
- From media post ID
MediaPost.from_media_post_id(context: FacebookContext, media_post_id: str) -> MediaPostProperties
Identity
id: str- Media post ID.
creation_time: int | None- Unix timestamp of when the media post was created.
url: str | None- Facebook permalink of the media post.
text: str | None- Caption / body text of the media post.
Engagement
reaction_count: int | None- Total number of reactions.
share_count: int | None- Number of shares.
comments_count: int | None- Number of comments.
reactors_visible: bool | None- Whether the list of reactors is public.
Media
Related
post: Post | None- The parent post that contains this media post, if known.
owner: Profile | None- The profile that owns the media post.
group: Group | None- The group the media post belongs to, if any.
Methods
Instance methods that fetch collections return a PaginatedIterator of model objects.
get_comments()-> PaginatedIterator[Comment]- Comments on this media post.
get_reactors()-> PaginatedIterator[Reactor]- Users who reacted to this media post.
Example
import facebook_gql_scraper as fgs
from itertools import islice
context = fgs.FacebookContext(cookies_file="facebook_cookies.json")
# Fetch a media post directly by ID
mp = fgs.MediaPost.from_media_post_id(context, media_post_id="1109890145162796")
print(mp.id, mp.url)
m = mp.media
if isinstance(m, fgs.Photo):
print(f"Photo: id={m.id} image_url={m.image_url}")
elif isinstance(m, fgs.Video):
print(f"Video: id={m.id} video_url={m.video_url}")
for c in islice(mp.get_comments(), 10):
print(c.text)