2

I m working on a Facebook App. Not a website.

I am trying to use Facebook C# SDK and trying to get Current User and Query Current User info. How do i do that?

Also, When i try to use an app it s asking for Adding the app, requesting permission to access data, how do i do that also?

Is there a comprehensive examples of these things?

DarthVader
  • 52,984
  • 76
  • 209
  • 300

2 Answers2

3

If you're stuck working with .NET 3.5, this will work:

var facebookClient = new FacebookClient(FacebookAccessToken);
var me = facebookClient.Get("me") as JsonObject;
var uid = me["id"];
wloescher
  • 4,503
  • 2
  • 25
  • 27
0

You need the access token. Once you get the access token make a request to me

var fb = new FacebookClient("access_token");
dynamic result = fb.Get("me", new [] { fields = "id" });
var userId = result.id;
prabir
  • 7,674
  • 4
  • 31
  • 43
  • what s the `fields` where does that come from? i m getting error for that. – DarthVader Apr 10 '12 at 19:31
  • it is passing parameters. rather then using dynamic parameters = new ExpnandoObject(); parameters.fields = new[] { "id" }; I'm using anonymous objects. I updated it to be in Get. – prabir Apr 10 '12 at 20:23
  • removing my comment above since you have it fixed. – DMCS Apr 10 '12 at 22:04
  • @prabir when i use CanvasAuthorize it redirects my page for oauth and comes back to my page. Do i have to do this in every page? is it ok to store the facebook user / access token in session? also how do you handle expiry of access token? – DarthVader Apr 30 '12 at 16:39
  • we don't support CanvasAuthorize in v6, you can find the v6 sample at https://github.com/facebook-csharp-sdk/facebook-canvas-aspnet-sample – prabir Apr 30 '12 at 19:39
  • Wouldn't I run into the same problem, that location isn't in the returned result? – Louisa Apr 04 '16 at 11:29