Export Facebook Fanpage Post’s Comments for Event Laravel 5.2

Table of Content

Recently, i got the requirement from company as below :

  • Access one page’s post on Facebook with page admin account and export the comments which match the specific format , for example UID:23456 LHMT and follow with tagging Facebook Users.

In this tutorial below, i will explain in details how i get all the Facebook comment for one page’s post and extract the correct information from comments using Laravel 5.2 and some packages like laravel/socialite, maatwebsite/excel.

Setup Laravel and needed packages.

Setup Facebook Application

I will not tell more details about “How to create one Facebook App for Website”, but in my example, i created one Facebook Application and result in Facebook App Id and Facebook App Secret.

Setup Laravel.

In this example, we using Laravel 5.2 and some packages as below :

  1. Laravel Socialite which needed for retrieve “Facebook Access Token” which required for permission to access Facebook Pages.
  2. Laravel Excel which needed for generate downloadable .xls report.

We install them using composer as below in composer.json :

Please follow those package links to see how to install them with Laravel.

Next i setup some variables which can change when switch enviroment on Laravel project .env:

Please note that POST_ID is Facebook Post Id we need to work with its comments.

Next i create one table call comments which store comments match our format :

with content :

And Comment.php model :

For the Facebook Authentication Flow, we create app\Http\Controllers\SocialAuthController.php as below :

We also add routes in app\Http\routes.php :

Please note that my comment message with fomart as above, so i will using PHP Regex as below to validate comment :

Next we result in app\Http\Controllers\MainController.php :

As you can see, i call the Graph API using Utility function as below :

When i get all comments for post, i will insert the new comments to database and generate Excel files for reporting.

The last thing which i missing is resources\views\welcome.blade.php :

2 thoughts on “Export Facebook Fanpage Post’s Comments for Event Laravel 5.2

  1. It is really a nice and helpful piece of info. Im glad that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing. cdecccbefgeg

  2. I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a great day. Bye efkbkcdbdkek

Leave a Reply

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