3

I am using https://github.com/darkwhispering/facebook-sdk-codeigniter which uses PHP SDK v5 to login with facebook. I would like to be able to save each user to a user database upon first login with basic information like email and name. Next I would like the data to update in the database if the data has been changed on facebook on further logins. Lastly I would like to be able to add more custom data for each user through my own website.

I am new to both PHP and CI. I know I need to make a modal. Please advise me.

This is the data I am pulling from the sdk $user = $this->facebook->request('get', '/me?fields=id,name,first_name,last_name,email')

I can call the name by using <?=$user['name']; ?>

John
  • 33
  • 4

1 Answers1

1

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.

Community
  • 1
  • 1
SanketR
  • 1,182
  • 14
  • 35
  • Thanks for the flow schematics as that would be the most important thing. I need to an answer more specific to CodeIgniter though. – John Sep 08 '16 at 06:28
  • I have edited my answer. Added some more details at the end of each point. – SanketR Sep 08 '16 at 06:39