0

I am running asp.net application on Facebook,which has multiple pages. On landing page I obtain access token. Question is how to persist that access token so that I can use it in other pages to access current user data. Current when I try following in other pages,

Facebook.FacebookAPI fbApi = new Facebook.FacebookAPI();
JSONObject currentUser = fbApi.Get("/me");

it breaks saying unauthorized.

Lix
  • 47,311
  • 12
  • 103
  • 131
Mandar Jogalekar
  • 3,199
  • 7
  • 44
  • 85

2 Answers2

0

You should just store the access token in your database along with a user ID reference. Alternatively you can just use a client side SDK like the Facebook Javascript SDK which will persist for you without having to go extra effort.

Matthew Johnston
  • 4,409
  • 2
  • 20
  • 27
  • considering that application will be used concurrently by many users. how to store current User id for current session Note:i cannot use sessions as i am using windows azure. so any other way? – Mandar Jogalekar Feb 17 '12 at 10:56
  • 1
    If you have built an app on Facebook.com, then every time that a user accesses your app, it will be sent a [signed_request](https://developers.facebook.com/docs/authentication/signed_request/) which can be decoded to receive a user ID (which could be matched to the access token stored in your DB) as well as the oauth_token which is the same as the access_token. You should use this. – Matthew Johnston Feb 17 '12 at 10:59
  • great help.. how to get the signed request in c# ? – Mandar Jogalekar Feb 17 '12 at 11:09
  • The signed_request is POSTed to any URL loaded in a Facebook app, so you just need to use the C# methods for retrieving POST requests. Here is a previous StackOverflow question which deals with that: http://stackoverflow.com/questions/976613/get-post-data-in-c-asp-net – Matthew Johnston Feb 17 '12 at 11:27
  • i cant get signed_request in post data any other way? – Mandar Jogalekar Feb 17 '12 at 11:44
0

I don't think you're using the most recent version of the API. It looks like you're using the deprecated one from https://github.com/facebook/csharp-sdk#readme

If you're using the latest one, then you can persist the access token. Grab the latest from: https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/#readme

DMCS
  • 31,720
  • 14
  • 71
  • 104