How to get likers and commenters of public posts

In this article, I would like to give a basic guide on how to download data from Facebook API about public posts of public Facebook pages. You may use such data for social network analysis, for text mining or basic statistics.

Firstly, you need to have a Facebook account, with a developer´s account. Facebook offers its guide how to set it up. You need to create your own app and get your unique token and id.

Then, you need to get an id of the Facebook page. One way how to get an id is to find it in the source code of the Facebook page. Then it is necessary to open Facebook Graph API Explorer. There, you enter a request for the list of posts for a specific page. The example is for the British magazine the Guardian.

In the end of the page, you may see the “paging” part of the results.

Click the link at “next”. Again, find the “paging” part of the results and copy the URL at “previous”.

You need to get these URLs for all desired Facebook pages. Create a list of these pages, with 2 columns: the name of the page (the column name “Name”) and the URL (the column name “URL”) and save it in the csv data format. Now we are ready to work with Open Refine.

The next step is to use Open refine to get the list of the most recent posts. If you managed to create a csv file in the last step, you may just import it into Open Refine and use this script.

The result would be a file with four columns – the page name, post ID, post text and post time. Export the project as a csv file.

Now, we need to get specific users for all posts. I use R for this activity. This is the basic code for getting data from Facebook API. However, you need to make several modifications.

 

You need to modify your working directory, your id, your token and your name of the file.

If you execute the code, the result is the csv file in your default folder. From here, you may work with the list of IDs of likers or commenters of your or any other public Facebook page.

Leave a Reply

Your email address will not be published. Required fields are marked *