0

Hopefully a quick one: Never implemented OAuth before and the client requires that once the user logs in (using facebook in this case) that this user is tied back to a record our end showing, for examples, which orders they have placed. I'm just trying to figure out the best way to do it.

Can anyone tell me if I can rely on the Facebook User ID from ever changing? Or point me in the direction of a decent article on the subject?

Mikey Hogarth
  • 4,672
  • 7
  • 28
  • 44

1 Answers1

2

The facebook user Id will always remain constant. To do something similar to what you want you would probably do this:

Step 1 - Authenticate the User

https://developers.facebook.com/docs/authentication/ - You would probably want to use the server side flow.

Step 2 - Get Permissions

https://developers.facebook.com/docs/reference/api/permissions/ - You will need to have the user_about_me permission to get their UserId. You add this to your authentication link above by adding &scope=user_about_me

e.g. http://www.facebook.com/dialog/oauth?client_id=YOURAPPID&scope=user_about_me&redirect_uri=LINKTOCOMEBACKTO

Please note your redirect_uri must be on the same domain as the settings in your app.

If you wanted to create an enhanced dialog box you can look at this:

https://developers.facebook.com/docs/opengraph/authentication/

Step 3- Getting the userid

If you are doing this inside a Facebook App then look at the userId in the SignedRequest.

Otherwise you use the Graph API. Here a StackOverflow question that shows how: How to get the Facebook user id using the access token

Community
  • 1
  • 1
Adam
  • 16,089
  • 6
  • 66
  • 109