I am developing an application that adds a tab to a specific fan page (it is not meant for use outside that fan page), but I need to get the ID of the user that is viewing the tab (The tab consists of a contest that users need to answer a few questions for and we want to save the answers to those questions so we can determine the winner).
I know that the standard facebook tab application only gets vague information about the user (language and a rough indication of the age of the user) but I was wondering how I would go about getting the user id of the user that is viewing the tab. I’d like to stress that this page is not installed on a users profile page, so I can’t get the ID like that.
I was thinking that there might be a way to ask for permission to get info about the user, but I have never seen this inside a tab before, only on canvas apps.
We can’t have this contest on a canvas page, we really need it to be on a tab page. The alternative would be to just randomly pick one of our fans as the winner, but I’d rather really fix this problem.
Any help regarding the topic of asking users for permission to access their personal data from an application tab would be greatly appreciated.
Thanks in advance,
Tim
In order to get any specific information about a user, that user would have had to authorise your application.
Based on you requirements I would recommend that you use the JavaScript SDK:
http://developers.facebook.com/docs/reference/javascript/
The following code will try to log the user in on load – if successful the response will contain the users id as well as the access token. If the user has not already auhtorised the application, an authorisation dialog will pop up. In this example the login is attempted straight after initialisation but it is much better practice to have
FB.logintriggered by explicit user interaction (eg from a link) otherwise the browser may block the popup.Edited to correct error pointed out by @ifaour.