In this blog we will learn how to analyze the comments of Public Facebook post using Facebook Graph API Explorer & R!

Facebook developer account required to get started with this Facebook Graph API .

If you don’t have Facebook developer account, you can upgrade your personal Facebook account to a Facebook Developer account from here this link.

After registering as Facebook Developer, go to “Tools & Support”->”Graph API Explorer”

To explore Graph API – Token & Permissions are required, so just click on the “Get Token”.


~ Courtesy Facebook Developer

As public profiles included by default in permissions, just click on “Get Access Token”.


Below is my access token, which will expire after some time. As shown in token info.

Graph Explorer

Now we have token,  let’s explore now.

Extracting Comments from the Public Facebook Post.

First thing you required is the Post Id of the post. See below steps to get the post Id.

Suppose below is the post, we want to analyze. Click on the Post Date Time. See below highlighted box. ~ Post Courtesy Facebook


Copy below Id. This is the post Id.


Go to the Graph Explorer.

Type “Post_id/comments” in below box & click on Submit.

6.pngYou can also give limit for number of comments to return, like this


My Input:


Output: Below are post comments in the JSON format.

If you want more comments click on “next” for next page of comments.


Click on “Get Code” to get the cURL code. Copy this URL, we will use this URL in R.

8.pngText Analysis in R 

R Packages required: 

install.packages(“RCurl “): It allows us to compose general HTTP requests and provides convenient functions to fetch data.

install.packages(“rjson”): It allows us to converts JSON object into R objects and vice-versa.

install.packages(“tm”):  A Mining Package for text mining applications within R. It offers a number of transformations that ease the tedium of cleaning data.

R Commands:


url used in above image is copied from cURL code from Graph Explorer.

Output: So the first page give me 25 comments only. We will analyze here only 1st page i.e. 25 comments only.


Cleaning & Analyzing Data:

Creating corpus & removing extra spaces, special characters & other unwanted things.


Creating Term Document Matrix:


Here is the 760 extracted words with frequency.


Creating Wordcloud: 

install.packages(“wordcloud”): For plotting a word cloud


In this Word Cloud we are taking only 100 words with minimum frequency of 2.



Graph API Reference ~Facebook Developer  For more details, please read this Link.

Feedback and suggestions are most welcome. If you have any feedback, suggestions or questions please comment.


Happy Learning!

26 thoughts on “Text Analysis – Facebook Post Comments

  1. I keep getting:

    “error”: {
    “message”: “(#12) singular links API is deprecated for versions v2.4 and higher”,
    “type”: “OAuthException”,
    “code”: 12,
    “fbtrace_id”: “GAs9tS7tqLz”

    Any thoughts?


  2. Hi, this is very interesting. I am looking for a way to analyze comments made on a public post on a profile post (not a facebook page). How should I proceed? The Original post is not under me, but I could ask for access to the other profile account is that is required.
    There’s been an awful debate regarding a social issue and I would like to be able to do things as to show figures regarding male/female views, Thanks for the post. Regards,

    Liked by 1 person

  3. Quick question here: Does this also work with Japanese characters? I’m currently searching for a tool to analyse comments in Japanese (I’m working with KH Coder atm but looking for alternatives).


  4. Hi, i came as far as to install the packages, then at the first step, R Commands, after library(“rjson”) I type url<- "http:(and the given url), and it throws: "Error: unexpected symbol in "curl -I -X GET \ …Couldn't get any further. Could you give me a hand?

    Liked by 1 person

  5. Hello!

    Thanks a lot for the elaboration.

    I have a question. FB has changed its privacy policy and I wanted to know if I can still fetch the names of the commentators or do I have to be the owner of the FB page?

    Thank yu in advance.


  6. I used to be recommennded this website through my cousin. I am now not positive whether this
    submit is written by way of him as no one else recognize such detailed approximately my difficulty.

    You’re amazing! Thank you!


  7. I was very happy to find this page. I wanted to thank you
    for your time just for this wonderful read!! I definitely appreciated every part
    of it and I have you saved to fav to look at new stuff
    on your website.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s