Folks,

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”.

1.png

~ Courtesy Facebook Developer

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

4.png

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

5.png
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

3.png

Copy below Id. This is the post Id.

2.png

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

Post_id/comments?limit=”.

My Input:

7.png

Output: Below are post comments in the JSON format.

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

7.png

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:

111

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.

output

Cleaning & Analyzing Data:

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

cleaning.png

Creating Term Document Matrix:

1111.png

Here is the 760 extracted words with frequency.

1112.png

Creating Wordcloud: 

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

lastt.png

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

Output:

lasttttttt.png

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.


Thanks!

Happy Learning!

28 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?

    Like

  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).

    Like

  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. {
    “error”: {
    “message”: “(#12) singular statuses API is deprecated for versions v2.4 and higher”,
    “type”: “OAuthException”,
    “code”: 12,
    “fbtrace_id”: “Aw1qRqKg1Nv”
    }
    }

    I am getting the following error. How to solve it. Please help me.

    Like

  6. 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.

    Like

  7. 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!

    Like

  8. 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.

    Like

Leave a comment