Categories: Tips

Scraping comments of a facebook post

You need to submit your app for review with required permission to access Facebook posts of page in which you aren’t admin; in live mode

This is a basic example of scrapping comments of a facebook post using python and facebook sdk

I hope you have python and know how to install a package.

Lets install facebook using pip

pip install facebook-sdk

We are proceeding directly in python

Before that we need an access token to connect to facebook.

Get the access token from here: https://developers.facebook.com/tools/accesstoken/

Access token is the pretty long string inside the textbox on the side where it is written “Access Token”

Now lets get those comments

graph = facebook.GraphAPI(access_token=’your pretty long string which you have copied now’)

post = graph.get_object(id = ‘post id’)

You can get the post id, by opening an url of a post in facebook

If url to a post is https://www.facebook.com/TimesofIndia/posts/10153947250687139 then, “10153947250687139” is the post id

print post

This will print bunch of details about the post including first 10 likes and first 10 comments

If you just need to see the comments

print post[‘comments’]

This will show just the comments.

If you need the remaning comments/likes, you will need to iterate the “cursors”, which doesn’t cover in basics. So just stopping here.

If you need further clarifications, please comment. If you wish to have Part 2 of this post, comment.

Njoy smile

Mithun

View Comments

Share
Published by
Mithun

Recent Posts

Quick release mount systems Compatibility chart

Plate Base FALCAM F38 Ulanzi Uka PGYTECH SNAPLOCK PeakDesign Falcam F38 ⬤ ✕ ✕ ✕…

7 months ago

Happy New Year 2025

I really thought I would keep up with the blog in 2024. But, it didn't…

8 months ago

Happy New Year 2024

Oh boy, there were a lot of things that happened this year. Like last year,…

2 years ago

Happy New Year 2023

This has become a abandoned blog. I will try to fix things this year. More…

3 years ago

Happy New Year 2022

Let me start off by saying, i have more blog posts this year than the…

4 years ago

Fix for xbox “This App Needs a Few Things That Are Missing on this PC”

This happened because your windows has run out of space. If you get this error…

4 years ago

This website uses cookies.