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”.
~ 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.
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.
You can also give limit for number of comments to return, like this
“Post_id/comments?limit=”.
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.
Text 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.
Output:
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!
Follow @shobhitsinghIN
Well done !
I did something similar on my blog, using transcripts of the republican presidential debates.
Keep up the good work, I’m a follower now 🙂
LikeLiked by 1 person
Thanks Man! following you back:)
LikeLike
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?
LikeLike
i had the same error and i put 2.2 in the direction instead of 2.4 and it works
LikeLike
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,
LikeLiked by 1 person
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).
LikeLike
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?
LikeLiked by 1 person
Don’t copy the curl -I etc, just copy the url (https://graph….)
LikeLike
{
“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.
LikeLike
Hello,
any tip how to analyze all comments – not only the first 25?
LikeLike
Hi, thanks for sharing this. How to analyze all comments instead of the first 25?
LikeLike
I’d also like to know if this is possible. It would definitely save a lot of time.
LikeLike
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.
LikeLike
you*
LikeLike
Why visitors still make use of to read news papers when in this technological
world all is existing on web?
LikeLike
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!
LikeLike
Excellent post. I used to be checkig constantly this weblog and I’m impressed!
Very useful information spewcifically the closing phase 🙂 I care
for such info much. I used tto be looking for thyis particular info for a long time.
Thanks and good luck.
LikeLike
Incrdible points. Sound arguments. Keepp up the great work.
LikeLike
Wow, this post is good, my sister is analyzing these things,
so I am going to tell her.
LikeLike
Wow! Finally I got a blog from where I be able to actually get helpful data
regarding my study and knowledge.
LikeLike
I am really glad to glance at this webpage posts which contains lots of helpful data,
thanks for providing such statistics.
LikeLike
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.
LikeLike
What’s up Dear, are you in fact visiting this web page
daily, if so then you will absolutely obtain nice knowledge.
LikeLike
Wow! This blog looks exactly like my old one! It’s on a entirely
different subject but it has pretty much the same page layout and design. Wonderful choice of colors!
LikeLike
What’s up, after reading this amazing piece of writing i am too happy to share my experience
here with friends.
LikeLike
Asking questions are actually fastidious thing if you are not understanding anything fully, except
this paragraph presents pleasant understanding even.
LikeLike
Everything is very open with a very clear clarification of the
issues. It was really informative. Your site is useful.
Thanks for sharing!
LikeLiked by 1 person
This website certainly has all the information and facts I wanted about this subject and didn’t know who to ask.
LikeLike