getting posts of public pages on Facebook
Solution 1
Check this endpoint of graph api: /{user-id}/posts shows only the posts that were published by this person
.
If you need an example, check this answer (implemented in python).
Any question, please do ask.
Solution 2
You can use the Facebook Graph Api. Here's an example to get all the posts from Stack Overflow page on facebook (You need access token for that):
curl -i -X GET \
"https://graph.facebook.com/v2.5/officialstackoverflow/feed?access_token=[YOUR ACCESS TOKEN"
The structure of the request is:
https://graph.facebook.com/v2.5/[Facebook Entity Id]/feed
You can use the Facebook Graph Explorer tool for testing and getting temporary access token.
Solution 3
To retrieve FB pages' posts by date, I use this function:
def queryFB (page_id, since_inp, until_inp, access_token=access_token):
""" retrieve the statuses of one page for a specified time range"""
# format since = "YYYY-MM-DD"T"HH:MM:SS+XXXX" (XXXX = time zone difference)
# format until = "YYYY-MM-DD"T"HH:MM:SS"
# format access_token = [app_id] + "|" + [app_secret]
# build URL
base = "https://graph.facebook.com/v2.11"
node = "/"
since = "since=" + str(since_inp)
plus = "&"
until = "until=" + str(until_inp)
fields = "fields=id,created_time,updated_time,message,likes.summary(True)"
token = "access_token=%s" % access_token
url = base + node + page_id + node + "posts?" + since + plus + until + plus + fields + plus + token
print(url)
(Of course, this will then need to be amended to use the output.)
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
Is there a way to get the posts of public pages on Facebook such as bars, clubs etc... and display them on my app?
I am working on a social media app, and I want to post information about real-time events in bars, clubs etc... Is there a way for me to use the posts of these joints from Facebook? Those pages are all public so there is no privacy issue.
-
Admin over 8 yearsSo basically I need an access token to do so (Which I can get only from the page by asking them for it) even if the page is set as public on Facebook?
-
jlnabais over 8 yearsYup you'll need a token for public pages on facebook, if you don't want one and you don't care about the UI of your website (if you're doing this to create a FB widget, for instance, you can you their html widget and change the page info dynamically.
-
Pablo Guerrero over 7 yearsThis works for officialstackoverflow. However I have tried it for other users and the feed field is missing. Why does this happen?
-
henrry almost 4 years@jlnabais can you help me for this problem?
https://stackoverflow.com/questions/62536699/how-can-i-get-posts-from-public-pages-with-graph-api