Take the 2-minute tour ×

Same as the title, what situation can use the getUser() function on facebook? P.S. I am using facebook php sdk api.

Why I ask this question is because I found out that if I not place the website inside the facebook.com, then getUser() function will always return null or 0.

Is that true? getUser() function only work in the website which inside the facebook.com?

Thanks. Newbie of facebook

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The getUser method should return the active facebook user id if there's enough data available to determinate that. This data can come from various places:

  1. signed request - this could come from the oauth authentication flow, or if its a canvas app, facebook embeds it into the http POST when your page gets loaded in the by <iframe>
  2. previously saved session data - if a previous attempt to determinate the user was successful, the resulting user id gets saved into a session variable
  3. access token - in some cases the access token can be used to determinate the user id

See the getUserFromAvailableData method for exact details, from a developer perspective the getUser() will return the current facebook user's id when the user is authenticated on facebook, and has your application installed/authorized. To achieve that see the documentation on login, for an external website, the best option is to use facebook's javascript sdk's login method to get the data needed for the backend (stored in cookies).

share|improve this answer
Thanks complex857. Is it means that if I not use the canvas page (iframe), then I will need to use the access token to get user id? P.S. graph.facebook.com/oauth/access_token –  Tony Tsoi Nov 5 '12 at 7:58
Well, yes and no. Yes for getting information out facebook you will have to submit a valid access token, but if you are using the PHP sdk you wont need to deal with it explicitly, if there's one available (coming from serverside auth flow, or js sdk) the php sdk will pick it up and add to your requests. –  complex857 Nov 5 '12 at 8:03

Your Answer


