Skip to main content

PostBase

The common base for Post and MediaPost.

PostBase is never instantiated directly. It appears wherever the SDK returns an item that could be either a Post or a MediaPost — for example Profile.get_posts() and Group.get_posts().

Creating​

PostBase.from_any_id(context: FacebookContext, any_post_id: str) -> Post | MediaPost
note

Internally tries Post.from_post_id() first, falls back to MediaPost.from_media_post_id() on InvalidIdTypeError — cost up to two HTTP requests. If you already know the kind, call the specific factory directly.

Properties​

Identity

id : str
Post ID.
creation_time : int | None
Unix timestamp of when the post was created.
url : str | None
Facebook URL of the post.
text : str | None
Body text of the 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.

Related

owner : Profile | None
The profile that authored the post.
group : Group | None
The group the post belongs to, if any.

Methods​

Instance methods that fetch collections return a PaginatedIterator of model objects.

get_comments() -> PaginatedIterator[Comment]
All comments on the post.
get_reactors() -> PaginatedIterator[Reactor]
Users who reacted to the post.

Subclass-specific fields​

Post only

title : str | None
Optional title, when the post has one.
media_posts : list[MediaPost]

Media posts already present in the post payload.

media_posts_count : int | None
Total number of media posts attached to this post.
get_media_posts() -> PaginatedIterator[MediaPost]

The complete paginated list of media posts attached to this post.

attachments : list[AnimatedImage | ExternalLink | Sticker]

Non-media-post attachments on this post.

MediaPost only

media : Photo | Video | None

The single media object wrapped by this post.

post : Post | None
The parent container post, if any.

Example​

Resolve an id without knowing whether it is a post or a media post:

import facebook_gql_scraper as fgs

context = fgs.FacebookContext(cookies_file="facebook_cookies.json")

item = fgs.PostBase.from_any_id(context, "1477518704237899")

if isinstance(item, fgs.MediaPost):
print("media post:", item.id, item.media)
elif isinstance(item, fgs.Post):
print("post:", item.id, item.text)