0

I'm using the Facebook PHP API to allow logins into my website. I am also allowing people to login/register using a built in form in my software incase they don't want to use their Facebook account.

I have this all working fine, my only issue is how do I attach the Facebook account to their account in my MySQL Database?

So for example Joe Bloggs wants to create an account on my website. Rather than filling in a form, he decides to login via Facebook. He does so. After he logs in via Facebook, it returns him to a page on my website where he can fill in the rest of his account details. It then saves his account and he is free to sue the website.

My issue is after he logs in with Facebook, creates and saves his account in the MySQL Database, how do I link his Facebook account and his account in my database?

When you login with Facebook, it returns a STATE, CODE and I can also retrieve an ACCCESS TOKEN using the API. However every time I login, these codes change. I thought there might be one code returned that I can use to store in the MySQL Database so all I have to do is match one of the codes to the database.

But I can't seem to do this. Am I coming at this all wrong?

Hope I'm making sense.

1
  • 3
    "It then saves his account and he is free to sue the website." Best typo of the day :)
    – David
    Apr 23, 2012 at 0:09

2 Answers 2

3

My issue is after he logs in with Facebook, creates and saves his account in the MySQL Database, how do I link his Facebook account and his account in my database?

Just store facebook user id in your table.

When you login with Facebook, it returns a STATE, CODE and I can also retrieve an ACCCESS TOKEN using the API. However every time I login, these codes change. I thought there might be one code returned that I can use to store in the MySQL Database so all I have to do is match one of the codes to the database.

You don't need to persist them ever. Only facebook user id is the identifier you need to identify user

2

Store their FaceBook UserID as an optional field in your user table to link their unique FaceBook UserID to a user in your application.

https://developers.facebook.com/docs/reference/php/facebook-getUser/

3
  • 1
    Small side note: php is not the only programming language everyone use ;-)
    – zerkms
    Apr 23, 2012 at 0:08
  • @zerkms Small side note, He said he's using MySQL so I assumed he was using PHP, I typically use .Net
    – Greg
    Apr 23, 2012 at 0:09
  • 1
    using mysql doesn't automatically imply that the programming language used is php :-) And even for php a lot of people (I don't know why though) use custom implementation, not the official sdk
    – zerkms
    Apr 23, 2012 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.