The following tutorial will show you how to export your Facebook friends to JSON, parse this data using PHP, and import it to a MySQL database table.

Download Facebook Friends Data

To get started, you will need to login to your Facebook account and go to the “Settings” link in the menu on the right side of the page (as illustrated in the image right of this text).

 

Once you are on the settings page, you will click Your Facebook Information in the menu on the right side of the page. After that, click on the “View” link in the Download Your Information section
(as shown in the screenshot below).

Download Your Facebook Friends

 

Next, you can unselect all, since we only want Friends data. Make sure that you only select Friends.
Also, make sure to set the format to JSON, then you can click the Create File button.

Facebook Download Data

After this, wait for the notification that your file is ready for download.

 

The Upload Form for JSON FILE

 

PHP Code to Upload  JSON File

The following PHP code will upload a file as long as the file does not exist in the target directory and as long as the file size is within the specified parameters.  Then, once the file is uploaded to the server the JSON data will be parsed in a foreach() loop and inserted into a MySQL database table.  The final piece of code, unlink(), deletes the .json file at the end of the script.