Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook C# SDK - .NET 3.5 & Dynamic objects

I have downloaded the Graph C# SDK for facebook, the examples are very helpful and easy to understand however i come unstuck when trying to use the dynamic object type as the return object for a FacebookApp.Get("me") call.

I'v never used dynamics before so i did a bit of reasearch and it seems they are new to Visual Studio 2010, which is the version i am using but i cant use the latest framework because of my production environment...

Is there a type i can use instead or is there a different way to go about this using the 3.5 framework? here is an example from the source files provided with the binary for the framework.

dynamic myInfo = app.Get("me");
lblTitle.Text = myInfo.name;

I get an error stating that i may be missing an assembely reference for type dynamic.

Any and all help is greatly apreciated! looking forward to getting to grips with this SDK!!

like image 558
Jarmez De La Rocha Avatar asked Jan 20 '23 18:01

Jarmez De La Rocha


1 Answers

If you want strongly typed objects there is a very easy way to do that. See here: https://gist.github.com/906471

var fb = new FacebookClient("access_token");

var result = fb.Get<FBUser>("/me");

string name = result.Name;

MessageBox.Show("Hi " + name);

[DataContract]
public class FBUser {
   [DataMember(Name="name")]
   public string Name { get; set; }
   [DataMember(Name="first_name")]
   public string FirstName { get; set; }
}
like image 186
Nathan Totten Avatar answered Mar 27 '23 17:03

Nathan Totten