How to Scrape Facebook Page Posts Data to Excel (Spy Competitor)


In this tutorial, I will teach you step-by-step how to scrape or extract ANY public Facebook Page Posts Data to Excel using Facebook Graph API without programming. It’s very easy just follow below steps.

You can use this trick to spy on your competitor’s Facebook fan page and download all its data to Excel for analysis.

In a hurry? Sign up for Quintly (Free 14-Day Trial For All Packages – NO CREDIT CARD NEEDED) and Scrape Facebook Page Posts Data to Excel in no time!

Following the tutorial you will be able to scrape the following data from your competitor Facebook page posts to Excel:

  • The number of likes,shares and comments for each post
  • The number of Facebook reactions (Like,Love,Haha,Wow,Sad,Angry) for each post
  • The message of each post (Facebook status messages)
  • Facebook post comments for each post
  • Facebook IDs for the users who have liked, commented on or shared a post

Below sample data was extracted from Donald Trump Facebook page.

scraped facebook data to excel using the graph api
export facebook likes,comments,shares and reactions data to excel

Okay,Let’s get started!

Step 1:Get Access Token from the Facebook Graph API Explorer

First,We need to get an access token from the Facebook Graph API explorer.We will use the token to get authentication to pull data from Facebook databases.This is a must do step!You will need to login using your private Facebook account.

After successfully logging in you will be redirected to the Facebook Graph API explorer 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

An access token which never expires

The above-generated token normally expires after 2 hours and you can always get a new one by clicking Get Token. 

But What if you want an access token which never expires?

You must create a Facebook for Developers account to be able to create an access token which never expires. Don’t worry it so easy than it sounds. Click this link and follow the wizard. After setting up your account then go to your  dashboard>settings>basic then click show App secret.

facebook app id and app secret

The never expiring access token will be your app ID|app secret .Don’t forget the pipe “|” between the app ID and app secret. For example, this is my never expiring access token 1179322318819014|a5axxxxxxxxxxxx.

Step 2:Get your competitor’s Facebook Fan Page ID from the Graph API

Facebook assigns unique IDs to every Facebook fan page. In this step, we will get the Facebook unique ID of our competitor Facebook fan page. Our competitor page for this tutorial will be Platnumz is a famous musician from Tanzania.

In order to get the unique ID, you will need to enter the following URL in your browser.

Replace the {fan-page-name} with your competitor fan-page-name (in our case, DiamondPlatnumz255) and replace the {access-token} with the access token from the earlier step. Access tokens have an expiration time, so if you find it has expired you will need to log in again and get a new one.

So the URL I entered on the browser is like this one below. You must use your own access-token, not mine, or it won’t work. (Truncated)

After that, you will get an XML format document like the one below. The ID we are looking for is at the top (see the red rectangular box) along with all of the other details of the page. Copy and save this ID somewhere because we will need it for the later steps.

Facebook page ID finder

Step 3:Pulling data from your competitor’s Facebook page

Now let us pull raw data from our competitor Facebook page. Make sure you completed Step 1 and 2 above.

We will need to use the following URL to get all the data. Be sure to replace all the information in brackets with the correct information for your competitor.The query will return data in chronological order{fan-page-ID}/posts/?fields=message,link,permalink_url,created_time,type,name,id,comments.limit(0).summary(true),shares,likes.limit(0).summary(true),reactions.limit(0).summary(true)&limit=100&access_token={your-access-token}

This query will return 100 rows of posts if they do exist. If the page has more than 100 posts then there will be pagination at the bottom of the results page allowing you to retrieve next set of data.

The brackets will be replaced as follows by the information we collected from previous steps such as Fan page ID and access token.

{fan-page-ID} = 204153042939851

{your-access-token}  = EAACEdE (Truncated)

The URL I entered on the browser is like this one below with all the fields filled in but since the access-token is so long it is not shown here in full. You must use your own access-token, not mine, or it won’t work,link,permalink_url,created_time,type,name,id,comments.limit(0).summary(true),shares,likes.limit(0).summary(true),reactions.limit(0).summary(true)&limit=100&access_token=EAACEdE (Truncated)

If everything is correct the browser will return a JSON response which looks like the window below

Facebook Graph API JSON result

Please observe the pagination at the bottom of the page as we will refer to it in step 4 for retrieving more data.

JSON response Pagination

Scraping data between specific dates

The previous query will return data in chronological order.What if you want to scrape data between specific dates?

Run below query make sure to change the since and until dates. Do include your page name/ID and access token as well.,link,permalink_url,created_time,type,name,id,comments.limit(0).summary(true),shares,likes.limit(0).summary(true),reactions.limit(0).summary(true)&until=2015-01-30&since=2015-01-01&limit=100&access_token=

Step 4:Converting JSON file to CSV/Excel

In this step, we will copy the returned JSON response and convert it into CSV or Excel using free to use online JSON to CSV/Excel converter.

While you are still on the JSON response page copy the JSON response and paste to the online converter just like in the image below.In order to make sure you are copying everything correctly on Windows click CTRL+A then CTRL+C or if you are using MAC Command-A then Command-C.

Click “Download the entire CSV” to get the converted data on your computer.

Converting Facebook Graph API JSON to CSV

As expected, we retrieved 100 rows of data and permalinks. We also received information about the messages, like count, comments count, share count,reactions count and the created time for each post.

competitor facebook page data

After removing columns with NONE,TRUE,FALSE and ranked I ended up with a nice looking CSV like below ready for analysis or further processing.

extract or scrape facebook data

If you want to extract more data you need to take advantage of pagination returned by the previous result.While you are still on the previous page of JSON result.Scroll to the bottom of the page till you see “paging” then copy the URL  after “next”.Copy everything starting from the https till before the closing “.

JSON pagination copying URL for next set of result

After copying it will be like below URL,link,permalink_url,created_time,type,name,id,comments.limit\u0025280\u002529.summary\u002528true\u002529,shares,likes.limit\u0025280\u002529.summary\u002528true\u002529,reactions.limit\u0025280\u002529.summary\u002528true\u002529&limit=100&access_token=EAACEdE (Truncated)

Unfortunately,if you enter this URL into your browser as it is,it will bring an error.Reason being it has these values(\u002528,\u002529) which can’t be interpreted by the browser.Actually,these values represent the ( and ) respectively.

So we need to clean the URL before entering into the browser.Copy and paste the URL into Notepad text editor for Windows or TextEdit for MAC.Then use the find and replace all feature.Find \u002528 and replace all with ( then find \u002529 and replace all with ).

Notepad find and replace all

Finally, I got this clean URL below which I can input on the browser to get the next set of 100 results.Remember to clean the URL everytime you want to retrieve more data.,link,permalink_url,created_time,type,name,id,comments.limit(0).summary(true),shares,likes.limit(0).summary(true),reactions.limit(0).summary(true)&limit=100&access_token=EAACEd(Truncated)D&until=1465296827&__paging_token=enc_AdDWxw7(Truncated)

Now that we have all the data we need we are ready to go on to the final step of the competitor analysis.

Step 5:Competitor analysis

Now it is time to do the analysis for the competitor’s page. In the previous step, we scraped data from 100 posts between 2016-08-18 to 2016-06-07 – that’s almost 2 months of data! However, you can go even further and collect more data depending on what you need. The competitor page was created in 2011 so there is far more data to pull and analyse.

Referring back to the goals we set at the beginning of the tutorial, below is what we obtained from the data:

Posts which received the most likes in descending order

Most Liked post

You can repeat the same process for the posts which received the most shares and comments. After that, it will be easy to tell which post type works best if you are aiming to get likes, shares and comments on your own content.

From the created time for each post you can also tell what time of the day and week works bests to achieve likes, shares and comments. You can also see the frequency with which your competitor updates his or her page.

Step 6:Exporting Facebook posts comments to Excel

Sometimes you may need to retrieve a competitor’s Facebook post comments to analyse how users or fans interact with certain posts. Through these comments, you can get a lot of insights into your competitor such as the weaknesses or strengths of your competitor’s products.

In order to do that, you will need to have the post ID of the post you want to retrieve comments from and the access token.

First, we need to get the post ID. Referring to the Excel spreadsheet we obtained in Step 4 above, you will find a column with posts ID named as ID.

Facebook Post ID

Refer back to Step 1 to get the access token if you still don’t have one yet.

The format of the URL will be like below{post-ID}/comments?access_token=XXX

Using the details of the example competitor page we used earlier, the URL will look like below. You can play with the limit parameter depending on the number of comments there are on the post, but there is a limit to it so you can’t input a very large number. (Truncated)

You will get the results in JSON format similar to the window below. You will then need to use a JSON to CSV converter to get the results into Excel format so they can be easily analysed.

Extract Facebook comments

If the post has a lot of comments then you need to play with the limit parameter as the Facebook Graph API has a limit on the amount of data it can retrieve at once. The exact limit varies so you may need a few tries to find the maximum.

If you have more comments than Facebook can retrieve at once the pagination option will appear by default at the bottom of the page as shown in the image below.You can then input this URL into the browser,this kind of URL doesn’t need cleaning as we did in Step 4.

Extract Facebook comments pagination

Step 7:Extracting Facebook IDs of users who like,comment or share a post

Step 7a:Extracting Facebook IDs of users who comment on a post

Referring to the result we obtained in Step 6 above, you will see that the result included IDs of all users who commented on the post.

extract facebook user IDs graph api

Step 7b:Extracting Facebook IDs of users who like a post

Now let us get the Facebook IDs of the users who like the post. We need to put the following URL in the browser again – again, make sure that your access token has not expired! If it has expired then you will need to get a new one by following the earlier steps. The only thing which has changed on the URL is swapping of “comments” and “likes” – all the other parameters do not change. (Truncated)

You will get a window similar to the one below with Facebook IDs of users who like the post.

facebook custom audience

Step 7c:Extracting Facebook IDs of users who share a post

Finally, we will get the Facebook IDs of the users who shared the post. The procedure is similar – we just need to swap “likes” and “sharedposts” and input the following URL in your browser. (Truncated)

You will get the following window which shows the sharer’s Facebook user ID and even who he/she shared with.

extract facebook user IDs graph api share

Extracting Facebook Reactions for each post into Excel

facebook reactions buttons

Now I will show you how to extract Facebook reactions for each post from your Facebook page or that of your competitor into Excel. The data will give you insights into how people react to different content in your industry and help you better tailor your own content.

Step 1:Sign up for a free account with Quintly

A free trial account will enable you to try all of the packages for 14 days without putting in a credit card. You will be able to export data into Excel/PowerPoint format, or alternatively you can sign up for a totally free account which allows you to analyse a maximum of 3 Facebook profiles and 1 month of data. However, the free account does not enable you to export data into Excel or PPT format – you can only export data from your free account into PDF/PNG/JPG format.

extract Facebook reactions

Step 2:Add a profile

After creating an account with Quintly, go to “Manage Profiles” and then click “Add Profile”.

quintly manage profiles

On the pop up window search for the Facebook page that you want to analyse and then click on “Add Selected Profiles” as shown below.

Quintly adding a Facebook profile

Step 3:Analysing Facebook reactions data

Click  “Facebook” on the dashboard menu, and then click  “Own Posts w/ Reactions Table”. You can also specify the date range (don’t forget that you are limited to within 30 days for a free account). Once you have done this, export the results into either Excel, CSV, JPG, PNG, PDF or PPTX for further analysis.

extract facebook reactions

Below is an example of exported data with each post’s reactions data in Excel.

quintly facebook reactions data in excel


Knowing the strengths and weaknesses of your competitor’s Facebook page is vital for optimising your own Facebook fan page.

I highly recommend you to try Quintly as your Professional Social Media Analytics tool. It provides in-depth analytics, competitive benchmarking, graphs and reports, not only for Facebook but across all Social Media platforms such as Twitter, LinkedIn, Google+, Pinterest and Instagram.

They have a free 14-day trial which doesn’t require you to put a credit card. Give it a try NOW before the offers expire.

You might also be interested in:

If you have any questions feel free to comment below.

Click Here to Leave a Comment Below 69 comments
Juan R - January 12, 2016

Hi Paulo, thanks for the very detailed post!

However I was unable to get the same results as you, I have tried many times with different pages and in the step “STEP 3:EXTRACTING DATA FROM FACEBOOK PAGE OF COMPETITOR” I always get an error, and no data 🙁

I get this:

Unknown table: STREAM (603)
(and a few more lines but not the data you get into your screenshot)

Any idea of what is happening?

Thanks for your time!

    Paulo - January 12, 2016

    Hi Juan,
    Write STREAM in small letters stream and it will resolve your issue.

Juan R - January 12, 2016

Sorry the text got deleted form the Repy, this is what I get on the browser in Step 3:

Thanks again,

Juan - January 12, 2016

Hi Paulo thank you very much for your reply, I changed to stream in non-capital but I get another error: “Requires valid signature (104)”

If you need more info I can paste the whole message or even record a video… just lust me know.


    Paulo - January 12, 2016

    Hi Juan,
    Make sure your access token is not expired.Re-login again to Facebook Graph API Explorer to check whether your access token is still valid.
    Otherwise you need to get a new one.

    Also make sure you don’t include any empty spaces after the = (access_token= ).

    Try again and let me know if the issue is resolved.

Juan - January 12, 2016

Hi Paulo, unfortunately I still have a problem, please check this video:


    Paulo - January 12, 2016

    Hi Juan,
    The way you put the access token is wrong in the last step.
    It should be access_token =CAACEde…
    Not access_token =…

    Please update if issue is resolved.

      Juan - January 12, 2016

      Hi Paulo, thanks you so much for your generosity!
      Issue resolved!

      Thanks again!

Shubhanshi - January 18, 2016

Hi Paulo,

Thanks for the step by step guide. I tried it but getting 104 error in xml, that is why I’m unable to fetch the data. Can you please help me in resolving the issue? I’ve uploaded the screenshot of error here you may check it.


    Paulo - January 19, 2016

    Hi Shubhanshi,
    This means the access token you are using is invalid. It has probably expired.
    Get a new token and let me know if it works.

keith - March 8, 2016

I got past this but now have this issue.
when trying to enter the formula to convert unix to human, it does nothing or am i doing it wrong you don’t specify how its doe so im thinking just selecting the box and replacing it with formula should work? screen shot attached in link.

keith - March 9, 2016

Paulo, still having trouble converting the unix time to gmt in excel any insight would be helpful.

Aakanksha - March 10, 2016

Thanks a lot buddy!

Daniel - March 31, 2016

Great article, it helped me a lot.

I was checking that book and it is a 2008 edition, is it really relevant to this day? I am interested in learning more, but I have no idea where to begin.


    Paulo - March 31, 2016

    Hi Daniel,

    Hi Daniel,
    I would advise you to read/peruse the ebook online before committing buying it.

    You can peruse same book or similar books online

    All the bests.

muci - April 19, 2016

Im wanting to purchase your progammer services
Can you contact me to discuss directly

    Paulo - April 19, 2016

    Send me your requirements through the contact form.

Rob - April 27, 2016

Hey Paulo, how do I save and open the XML file? I successfully got the data but now am having trouble loading the XML into a table like you have in excel.

Thanks for the help!

    Paulo - April 28, 2016

    Hi Rob,

    After saving the XML file anywhere on your PC/MAC then Open it with Excel.Pop windows will open asking you if you want to open the XML file as a table.Click OK.Then another pop up window click OK again.


Shikha - May 9, 2016

Hi Paulo,

Thanks for the fantastically simplified article. But I am facing the below error. Re-login didnt work.

error_response xmlns=”” xmlns:xsi=”” xsi:schemaLocation=”“>
Requires valid signature (104)

    Paulo - May 10, 2016

    Hi Shikha,

    This means the access token you are using is invalid. It has probably expired.So you should re-run the steps to generate an access token.

misha - May 14, 2016

Hi Paulo.

I need to count unique people who like, share and comment within certain period. For example, for April 2016. I need this information for my research. Really appreciate if u can give me the programming script.Thank you

ICG - June 12, 2016

Hi Paulo,

This really helped me a lot with my final project. Thank you so much! But I was wondering wether it would be a similar way to get the transcriptions of the facebook posts on a different column in excel as well. I mean, not only the links and likes and comments but also the text of the post.

That would be great and will save me tons of time. Thanks in advance!!

    Paulo - June 26, 2016

    Thanks for nice comment,
    You can see from the query I added message

    Try this one permalink,like_info,comment_info,share_info,created_time,message from stream where source_id= and created_time < your-time and actor_id= ORDER BY created_time DESC LIMIT 20000&access_token=

      ICG - June 26, 2016

      Works perfectly! I figured it out earlier but thank you so much!

      Now I was wondering if there’s a way to know how many fans had the page on a given date? For example for 1st of january and 31 december. I’ve searched a lot but unfortunately cannot find a query to that 🙁

      Thank yo so much again! Your tutorial was amazing for my project!

Marsh - June 15, 2016

Many thanks for your wonderful tutorials, Paulo. They are clear and well explained. Keep up the good work.

Brian - June 23, 2016

Hi, thanks for the guide. I was able to follow it successfully but had one issue during step 2. It works fine for most pages, but runs into a problem if the page name contains dashes (and possibly other characters). For example, the page name in does not work in the graph api URL. Do you have any idea how to correct this? Thanks again.

    Paulo - June 26, 2016

    Hi Brian,
    For your case.
    Click the profile pic of the page.Go to the URL the second string of numbers from right of the URL (56490240879) is the page ID.
    FanPage ID

Nino - August 3, 2016

thanks for this post, very helpful. But I have a question: is there any way to use a non-expiring token? It’s very annoying generate everytime a new one.
Thank you

    Paulo - August 3, 2016

    You can create an access token which never expires by concatenating the App ID from a user-created App and the App Secret(app_id|app_secret).
    You can read more about Access Tokens.

      Nino - August 4, 2016

      I did it,
      but then I get an error message:

      REST API is deprecated for versions v2.1 and higher (12)

      Can you please help me?
      Thank you!

        Elio - August 18, 2016

        Hi Paulo, your post it’s very usefull!, until the last week, worked perfectly but at moment show me the same error that Nino (REST API is deprecated for version v2.1 and higher (12)) when I executed the sentence in step 3, do you know how I can fix?

        Thank you!

          Paulo - August 19, 2016

          Hi Elio,
          The tutorial has been updated.Enjoy
          Also check this tutorial using ready made Python scripts and leave me a comment there.

Chris - August 17, 2016

I’m in Nino’s boat this morning. It was working last night, but not this morning.
I checked the key (logged in, logged out, generated a new key).
Now I’m getting, “REST API is deprecated for versions v2.1 and higher (12)” I double, and triple checked :-/

    Paulo - August 19, 2016

    The tutorial has been updated using the Graph API.I have also written another tutorial using ready made Python scripts.

Tim - August 17, 2016

Hey There,

this doesn´t seem to work anymore since FQL is no longer available by Facebook.
Do you know how to do this with the graph Api?

    Paulo - August 19, 2016

    Hi Tim.The tutorial has been updated.Enjoy
    Also check this tutorial using ready made Python scripts and leave me a comment there.

      Tim - August 19, 2016

      Hi Paulo,

      Thats great, works just fine!
      Love your blog posts, keep up the good work!

Raymund - August 20, 2016

That was awesome work! Used your code and worked like a charm! Thank you very much!

Becky - August 24, 2016

Hi Paulo,

I noticed I am not getting the permalink with this new method. Do you know, is there anyway to get the permalink to the post? I need to screenshot the actual post for data collection….

Turbin - September 15, 2016

Hi Paulo,

what a great tutorial.. i follow the steps and it works..

but after doing step #7 a,b and c, then do i have to copy and paste the ID one by one to .txt file ?? in order to be used at Custom Audience..

or perhaps you have another method to do that? because there are hundreds of ID likes, comments, shares, and takes time doing that..

Thanks for your respond 🙂

    Paulo - September 16, 2016

    Hi Turbin,

    Copying and pasting isn’t effective way if you want to collect large data set.
    I recommend you check this tutorial and modify my scripts.

    Michael - September 30, 2016

    Hello turbin,

    Do u also want to use those ID”s for facebook ads, and target a very niche audience?

    If so did u had results by doing so? and is this still legal to do?



      Paulo - October 2, 2016

      Hi Michael,

      I haven’t created any custom audience myself.

      But you can refer to this post,it might help.

fauzy - September 22, 2016

Hi Paulo,
how to add friends using uid list after Extracted?

michael - September 30, 2016

Hello paulo,

Great guide.
few questions:

1. Can i use the id to use them in a facebook ads campaign to sell any products?

2. if i extract for example 10000 id from a fan page. can i legally use those id to target them with facebook ads?


ilana - October 4, 2016

Hello Paulo,

When I’m redirected to the Facebook Graph API after logging in I do not get the access token generated,

Please can you give me a hand?

thanks for sharing this amazing tutorial


Anita - October 4, 2016

Thanks for this guide! I’ve used it a lot. However, after the guide was updated I can’t seem to convert the data into CSV. When I convert the JSON file to CVS, Excel shows up with a bunch of text.
Previously I had no problem organizing the data in Excel.

(What happened to the previous version of this guide anyway?)

    Paulo - October 4, 2016

    Dear Anita,

    Facebook deprecated the FQL which was used in the previous version of the guide.FQL used to return data in XML which is easy to process with Excel.
    Please check this other tutorial and let me know how it works for you.

Shiny - October 15, 2016

Please help me

ashutosh srivastava - November 10, 2016

Is there any way in which we could extend the life spam of the access token?

Elizabeth - December 17, 2016

Does this work for groups? I’ve tried the above with the group ID in the fan page id place and get the following error:

“error”: {
“message”: “Invalid OAuth access token.”,
“type”: “OAuthException”,
“code”: 190,
“fbtrace_id”: “C6GA1OwaNy8”

    Paulo - December 17, 2016

    Hi Elizabeth,
    For groups, use this query.,link,permalink_url,created_time,type,name,id,comments.limit(0).summary(true),shares,likes.limit(0).summary(true),reactions.limit(0).summary(true)&limit=100&access_token=

    The above query string only works for public groups.

    Check this tutorial on how to get the group_ID for a public group

      Elizabeth - December 18, 2016

      It’s not public but I am a member. How would I scrape a group I’m a member of?

        Paulo - December 18, 2016

        For private groups, I haven’t yet figured out a way to do it using the API. If I find a solution will update you.
        But…If you know some programming you can automate the infinite scrolling and scrape the loaded html into csv.

Flame - January 11, 2017

Hi Paulo,
I’m from Italy. I just tried to apply your detailed instructions, but I was stopped just at the beginning!

After obtaining an access token using my private account, I just tried to submit the query with the page-id and my token access but I just received an OAuthException message.

Can you help me?

I need to extract text from FB posts in order to apply Linguistic Analysis on textual data, for academic research purposes.

Thanks in advance.


    Paulo - January 12, 2017

    Hi Flame,

    Please send the page ID through the contact form and I will check.

Josh - February 9, 2017

Hi Paulo, im having trouble getting more than 1000 results when trying to scrape the IDs of people who have liked a particular post. I change the limit on the query but it still only returns a max of 1000. is there a way around this?

deepali - March 3, 2017

this is very helpful demo.



Leave a Reply: