How to save Facebook user basic information to database with CodeIgniter 3.1.0 How to save Facebook user basic information to database with CodeIgniter 3.1.0 codeigniter codeigniter

How to save Facebook user basic information to database with CodeIgniter 3.1.0


Here would be your workflow.

1. I would like to be able to save each user to a user database upon first login with basic information like email and name

You can set facebook username as a unique identifier in your database. This way, you can perform a check for the user whenever he logs in to your application. Create a library for authentication and use it to perform checks for access permissions in your controller functions. Use a model to update the database once the data is validated successfully.

2. I would like the data to update in the database if the data has been changed on facebook on further logins

You can write a script similar to above to match the data fetched from facebook whenever user logs in. For images you can use graph api https://graph.facebook.com//picture?redirect=false and save the image name or id whichever is unique in your database to match it with the current id.

OR

You can write a cron to poll the facebook api and check for the details using access tokens. (Depends on which fields you want to update and how much restriction access facebook has in their api)Is there a way to check if Facebook access token is still valid?.You can use the same library to create functions for this check to be performed. Use the same model to perform data updates.

3. I would like to be able to add more custom data for each user through my own website.

This would be your normal PHP code and will not deal with facebook. Once the user is logged in, you can allow him to enter more details through forms on your website. This will be another controller in your application which displays a user form as a view and connects to a model to update the database.