views:

189

answers:

2

In my facebook canvas applikation, i store the access token in session. (I use ASP.NET MVC)

But i want to store the access token in a database along with the facebook user id that i can save different access tokens for different facebook users accessing my application.

So when i query the facebook user id and if it doen't return any access token, i request permissions and get the access token for that user.

How do i access the Facebook UserID for the user accessing my canvas application before doing any authentification?

+2  A: 

You can't access FB user id if the user doesn't grant access. Imagine that it is allowed without permission, you can access basic information about the user, and that makes the permission meaningless.

grayger
This is correct. Without the user providing the "basic access" permission, then they are anonymous to your application.
Peter Bailey
A: 

Write this code in the ASP Page_PreInit event,

    long fbuid = long.Parse(Request.QueryString.Get("fb_sig_user"));

If the your is logged in, then you can easily get the user_id from the query string.

Kind of a duplicate: http://stackoverflow.com/questions/3504943/facebook-get-user-id-from-application-tab/3837457#3837457

Adi_aks