Simple Facebook Graph Api Example in ASP.NET C#
Announcement: We just launched a new Email To SMS Alert system, and the best news is we have a free version. Go to http://www.totxt.com to test it out.
Here is an example VS 2010 project that creates strongly typed objects using Newtonsoft. Json Deserializer.
Steps
- Create your facebook app on facebook (read instructions http://phpplanet.org/how-to-create-facebook-application/)
- Download my example codehere
-
Copy and Paste your appid and secret key into web.config
-
Run the default.aspx and get your auth code and paste into “FacebookSvc.cs
TestMethodGetAllData() and GetFriends()
-
Now you can run all the methods in FacebookSvc.cs (get friends, get news
feeds….) or run default.aspx and click “show friends”
-
I suggest running TestMethodGetAllData() using TestDriven.net, but you can run
it how ever you want
Here is some example code just to show how easy it is...
var friends = GetFriends(token,
username);
foreach (var friend in friends.data)
{ Response.Write(friend.name) }
The code is very maintainable because it just uses de-serialize like this
var listOfFriends = JsonConvert.DeserializeObject<Friends>(strJson)
Enjoy …. ~alex