How to extract Facebook page likes history by countries to Excel

1

In this tutorial,I will show you how to extract any public Facebook page likes history to Excel.For example, how many fans did page X have 5 months ago and the countries of the fans.

In a hurry? Sign up for Quintly (Free 14-Day Trial For All Packages – NO CREDIT CARD NEEDED) and download historical fans data in no time!

Facebook page likes history

Let’s get started

Getting Facebook page likes history by countries using Graph API

Step 1:Get access Token from the Facebook Graph API explorer

In order to retrieve Facebook data through their Graph API, we must get an access token from the Facebook Graph API explorer.The access token is a special key which the app uses to call the Graph API on behalf of you the user.

The Graph API  is the primary way  to get data in and out of the Facebook platform.The Graph API Explorer is a tool which makes it really easy to use and  traverse the Facebook Graph.

To get an access token open Facebook Graph API explorer and log in using your Facebook account(if you are not logged in) otherwise (if you are already logged in) you will see an interface as shown in the window below.

You will see the access token (see the red rectangular box below) already generated for you. Copy and paste it to store safely somewhere because we will need it in the later steps.

Graph API access token

The access token is valid for a certain period of time normally like 1 hour or 2 then it expires.If it expires you need to get a new one by clicking “Get Token”

Access token expiration time

Step 2:Check Facebook page likes history by countries

We will use Facebook Insights API to check Facebook page likes history.As per Facebook “the Insights API only offers two years data retention. Insights data older than two years is subject to removal”.

Now it is time to check Facebook page likes history by countries.We can get the data using the following query which will return data in JSON format.Then we will convert the JSON data to CSV or Excel for easy analysis.The query can only return data for not more than 93 days duration otherwise, it will return an error  “Time range too long”.

The query will return lifetime aggregated Facebook location data, sorted by country, about the people who like your Page (Unique Users).

https://graph.facebook.com/v2.6/pagename/insights/page_fans_country/lifetime?&since=yyy-mm-dd&until=yyyy-mm-dd&access_token=xxx

Replace the bolded text with your info.

For example, I want to get Barack Obama Facebook page likes history  by countries

His page name is barackobama

barack obama facebook page

I want to get data since=2016-06-01 until=2016-09-02 (Total 93 days:2016-09-02 not included)

My query will be like below

https://graph.facebook.com/v2.6/barackobama/insights/page_fans_country/lifetime?&since=2016-06-01&until=2016-09-02&access_token=EAACEdE(truncated)

And below is a screenshot of the results I got on my browser in JSON format.Copy all the results in a text editor as we will convert them to CSV/Excel in the coming step.You can convert the countries abbreviations to full names by referring to this website.

facebook page likes history by country json

You can get next set of results by copying the URL after the previous or next text and pasting the URL into the browser.Do make sure to copy the result into a text editor.You can do repeatedly until you collect enough data or all the data(only 2 years back data available from the current time).

paging Facebook JSON data

Step 3:Converting JSON to Excel

There are many free web-based tools to convert JSON to Excel.In this tutorial, I will use this website for conversion.Go to their website and paste the JSON obtained in the previous step like below image.And the page will automatically start converting.

JSON to CSV converter

Another window will open up with your data already in CSV ready to be downloaded to your computer.Click the “Download” button.

json to csv download button

You can clean the Excel sheet by converting the countries abbreviations to full country names.You will have something similar to below image.

Facebook page likes history

Conclusion

You can extract more interesting data from Facebook please check below tutorials.

How to extract data from Facebook pages to Excel such as likes count,share count,reactions and comments

How to download Facebook photos and videos from Facebook

If you have any problem please let me know in the comments below.

Click Here to Leave a Comment Below 1 comments
Jean - January 27, 2017

Hi,

Thanks for your scripts.

Have you got any idea why the number of likes obtained via this method doesn’t match the number of likes on the facebook page themselves?

Best,

Jean

Reply

Leave a Reply: