Artisan
Artisan

Reputation: 4112

Get up-to-date facebook user's information using the Graph API

I like a create a simple web blog (written in PHP), to satisfy my blog's audiences, he/she should only have to register to my blog once (using his/her Facebook user account), after then he/she wouldn't need to re-login to my blog again in the future

There are steps I can think of

  1. User visit the login link created using new FacebookRedirectLoginHelper($facebook_redirect_url); just as in SDK's documentation
  2. After the login process, my blog then create facebook session using $helper->getSessionFromRedirect(); to access the Graph API to access user's public information, e.g. email, profile name, profile picture, etc.
  3. My blog then store all user's public info into the blog's database
  4. My blog then write his/her facebook ID to the cookies
  5. For the next visits, my blog just has to use the facebook ID which comes with the cookies to authenticate into my blog

I think the above steps seem to meet my requirement, but if there is any suggestions please give me some ideas to improve

I wouldn't need the blog user to re-login ever again because I have all information I need in the blog's database, but the question is what to do to let my app get up-to-date information of the user (e.g. profile's picture, etc) I cannot use his/her access token to access the graph API anymore because it will always become expired

Please guide me some ideas for the solution

P.S. The most important requirement is to offer single registration & login to the blog's user, unless he/she manually logout

Thanks.

Upvotes: 0

Views: 340

Answers (1)

Azeez Kallayi
Azeez Kallayi

Reputation: 2642

You can get the public information of any user if you have their facebook id or user name. For example you can get my public details using the below code:

https://graph.facebook.com/AbdulAzeez86

Here you can change username with id, which you will keep in your database. To get the profile picture of a user you can use the below code:

https://graph.facebook.com/AbdulAzeez86/picture?type=large

Here also you can change name with id and type with any of these (square,small,normal,large)

To get the contents you can use curl ,file_get_contents etc.

Upvotes: 1

Related Questions