About/Contact

Steve Trefethen

Steve Trefethen is CTO at Wanderful Media.
Contact me

View my LinkedIn profile



Calendar

<<  June 2013  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.



Developing Facebook applications in C# with ASP.NET

June 10 2007 9:04AM

Updated VS.NET 2010 Facebook Starter Kit

I mentioned previously I've created my first Facebook (FB) application (which is still under development) but I've learned a lot along the way. I haven't found the Facebook documentation very useful at all and have gleened a lot through Google, the Facebook developer group and simply tinkering with things. As a result I've put together some steps I think could help save you some time if you're looking to write a Facebook application using ASP.NET and C#. Btw, you'll get no help from facebook.com regarding ASP.NET development.

One thing that took me awhile was understanding how an FB application appears on your profile page. I eventually realized that FBML can be used to push markup onto a users profile page. This block of markup can be set at the time you create a new application though the first time around, if you're like me, this may see a bit confusing keep in mind I'm new new to FB itself so a lot of this was confusing. From the FB toolkit you can also use the method setFBML to programmatically set this block of markup. Needless, to say being used to MSDN documentation FB doc leaves a lot to be desired. That said there are a few tools you can use to play with the API as well as sample your FBML markup.

Facebook start app screenshot

At any rate, here are the steps I followed to get my application working. Note, the project includes support for Microsoft AJAX so you'll want to have that installed as well although you could just tweak the .aspx and web.config files and use it without AJAX. The screenshot illustrates what you should get when your done. NOTE: In the following steps several links won't work unless you have an FB account.

UPDATE: I've created a new page on my wiki with updated steps and a VS.NET starter kit to make this much easier.

  1. Sign up for a Facebook account
  2. Add the Developer application to your account (you need an account for that link to work)
  3. Click Developer application from the left column and select click Set Up New Application
  4. Enter the Application Name and expand Optional Fields
  5. Under Optional Fields
    1. Set your callback URL http://localhost... will work just fine for development
    2. Select "Use iframe"
    3. Click Yes for "Can your application be added on FaceBook"
  6. Under Installation Options
    1. Check "Developer Mode"
    2. Under Site Nav use the same URL from Canvas Page URL (see Optional Fields)
    3. If you use my template set Edit URL to your Canvas Page URL + /settings
  7. Click Save then from the Developers Application browse to My Applications
  8. Click View About Page then click Add Application. This will allow you to easily work with your application during development.
  9. Download the Facebook Developer Toolkit from Microsoft
  10. Download my C# ASP.NET app to get you started or generate the boilerplate code for handling login (sorry I don't do VB.NET)
  11. You'll need to add a reference to the Facebook assemby to this project as I didn't want to include it as it being updated frequently right now
  12. Open Default.aspx.cs and fill in FACEBOOK_APPKEY and FACEBOOK_SECRET from your application's page on Facebook.
  13. Fire up the browser and hit your http://apps.facebook.com/<your_app_name> and you're off!

Please let me know what problems you have or let me know if these steps need tweaking.

Was this helpful?

[Updated: June 11, 2007] Added link to an update page on my wiki with this content.

[Updated: Feb. 24, 2008] Since this post was written I've created two VS.NET starter kits, one for Facebook Dev Toolkit and Facebook.NET. Here are some additional links:

FacebookDel.icio.usDigg It!

Comments (53) -

6/10/2007 10:48:41 AM #

Can you elaborate which tools you used during the process? BDS 2006? Or is there some "Facebook IDE" you can develop in. I never heard of it, so your blog post is rather interesting to consume new information on the topic...

Holger Flick

6/11/2007 9:32:50 PM #

Facebook is agnostic as long as your tool of choice can handle REST though from their web site they promote PHP and Java with minor mentions of other frameworks. I'll avoid the religious debate on tooling as I don't believe in religion when selecting development tools. My current favorite happens to be Delphi from CodeGear though YMMV.

Steve Trefethen

7/10/2007 8:09:53 PM #

Hi Steve,

First of all, thanks for sharing your experience!

I tried to run your application acc to your instructions, but for some reason the method "GetUserInfo" returns the following error:

The underlying connection was closed: An unexpected error occurred on a receive.

Do you have any suggestion what I should do?

Thanks again,
Eyal

Eyal

1/25/2008 7:10:35 AM #

hi
I am new to Facebook...I developed desktop application in .Net

i am getting the Friendslist,i used the following code in page_Load,
friendList1.Friends = facebookService1.GetFriends();

I am getting error: NullvalueExceptionHandled
Object Reference not set to be an instance of an object

how to use my application in Facebook...

Thanx
vidhya

Vidhya

1/25/2008 3:03:15 PM #

Thanks for helping us. This is great article. Now I like to add Profile box via asp.net, C#. I could not find any sample code for it. How can I design profile box via C#.net? Do you have any sample project? Thansk.

Young

1/25/2008 4:51:14 PM #

Young,
  I'm not in a position where I can provide free Facebook technical support. If you're interested in consulting please let me know and I'd be glad to help otherwise, I'd suggest the Facebook Developer forums.

Steve Trefethen

1/31/2008 9:24:16 PM #

What are your experiences with FBML and ASP.net controls?

I've been tinkering also and have been finding it somewhat difficult to debug some issue partiularly when it comes to ASP.net webcontrols. Some work others do not.

I'm guessing its all related to the FB version of javascript and its attempts to create javascript namespaces but have yet to come to any concrete conclusions on what works and what doesn't and workarounds etc.

dan

2/20/2008 9:59:08 AM #

I am creating application using facebook.net in iFram mode.What i have a problem is when data grow a ugly scroll bar appear on right side of application. What i want is to hide those ugly scroll bars that get with an Application.

Kashfi

2/20/2008 5:26:38 PM #

Kashfi,
  I have information on http://www.stevetrefethen.com/blog/email.aspx">this page where to ask questions related to Facebook Development.

Steve Trefethen

2/25/2008 1:39:54 AM #

I'm sorry, I don't know what you mean to do with this code. Are we supposed to create an empty project in Visual Studio Express and put your code in it?

David

2/25/2008 6:27:47 AM #

David,
  Refer to the page I mentioned in the post with updated content. I've since created a www.stevetrefethen.com/.../...%20in%20ASP.NET.ashx">VS.NET starter kit you can use instead.

Steve Trefethen

2/26/2008 3:57:41 PM #

how can we use multifriend selector to invite friends

rocky

2/26/2008 7:37:35 PM #

rocky,
  In an IFRAME implementation you can't use FBML so the multi-friend selector isn't an option, you'll need to implement that on your own. For more help, I'd recommend the Facebook developer forums.

Steve Trefethen

3/8/2008 9:32:52 AM #

see www.siccolo.com/.../...lication-development-1.html">Facebook Development with FBML, .NET, C# on
http://www.siccolo.com/articles.asp">Siccolo development

siccolo

3/25/2008 10:10:52 AM #

Hello,

I am developing a facebook application on .net technology to do character analysis.Once the survey for this is done, the application result needs to be appeared in the profile page.I tried html iframe, <fb:iframe, <fb:ref etc...But Nothing worked out.

I know there is a technique to display dynamic contents in profile page from an external URL..

Please reply as soon as possible..

Its Very Urgent...

Please....

Thanks...

Fabeena Thoufeeq

Fabeena

3/26/2008 5:46:35 AM #

Hello Steve,
U have any idea regarding my above question?...

Thank You..

Fabeena

3/26/2008 5:19:07 PM #

Fabeena,
  You should post questions like this to the Facebook developer forums.

Thanks!

Steve Trefethen

3/28/2008 12:08:13 PM #

hi sir,
good evining i wanted to do a project of asp.net using c#.net and i need some help from you

vinay

4/2/2008 9:44:14 AM #

Hi,

I am trying to developed a local facebook application.I had also created one application in facebook and also set a canvas url as http://apps.facebook.com/Mypage.

But when go thought this url hall facebook login page is display in canvas.Whenever i am login for my page that time canvas page is show me logged but outer page not.I have also screen shot for that but not able to send you.  


Thanks,
Regads
Soni Umesh
Devloper

Soni Umesh

4/2/2008 3:03:18 PM #

Soni,
  I recommend posting support questions like this to the Facebook developer forum as you'll get a lot more eyes looking at the problem.

Steve Trefethen

4/3/2008 3:02:09 AM #

Thanks for being such a big help for everyone Steve.

I have a question about testing Facebook Apps. I have already deployed my facebook app so in my Facebook settings, I have a live Callback URL.

When I make updates to the program and I want to test them locally on my machine, I need to change the Callback URL to http://localhost... but that breaks the application for all of the 'real' users while I test.

Is there a good way around this? Thanks!

Phil

4/3/2008 6:21:42 AM #

Hi Phil,
  Thanks for the kind words. I think there are a few things you can do including creating another application on Facebook that simply uses a different callback URL. Additionally, I'd recommend designing your application in such a way that the portions that don't require access to Facebook can function without that requirement allowing you to test those features in isolation. Your question leads me to believe that it would be valuable for frameworks such as Facebook Dev Toolkit and Facebook.NET to provide a mock interface which would more easily allow for testing outside of the  Facebook server (perhaps something already exists). I'm sure something like that could be done and in fact sounds like an interesting project.

HTH

Steve Trefethen

4/18/2008 8:34:25 AM #

Hi Steve,

Are there existing applications in facebook created in ASP.Net? If so, can you name some of them? So that I can test if apps built in ASP.Net is as stabel or as fast compared to other platforms.


thanks

Paul

4/18/2008 2:48:38 PM #

Hi Paul,
  Since Facebook applications run in an IFRAME it's less obvious they're ASP.NET apps. It's entirely possible some FB apps you've used are ASP.NET apps.  Is it really necessary to demonstrate that ASP.NET is fast and stable when running as an FB app when MS, Dell, MySpace and many other major sites all use it?

Personally, I don't think it's an issue. If you're really feel your FB app is going to scale to such size as to raise concerns about the scalability of ASP.NET I'd say you should focus on other areas first like how you're going to write such a scalable app in the first place. Next, I'd worry about the hosting provider and whether or not they can supply you with scalability, sufficient bandwidth, load balancing, failover etc. Now, to me those would be real concerns for a wildly successful app.

Steve Trefethen

5/12/2008 4:14:39 PM #

from where i can download library version 1.3?

sakina

5/15/2008 9:37:15 AM #

I have a problem with Ajax in my ASP.NET application.
I add AjaxToolKit to my app and use UpdatePanel on default page.

I recive JavaScript Errors:
Line: 41
Error: 'Sys' is undefined

Alex

5/27/2008 2:13:30 AM #

Hi Steve,
Is there any new .net toolkit version covers the changes in Facebook API?

Facebook will launch the new version soon. I think the current toolkit may not work correctly with the new changes.

Mido

5/27/2008 3:56:56 AM #

Hi Mido,
  No, at least not that I'm aware of. Unfortunately, I too have major concerns about the Facebook Dev Toolkit. I've attempted to contact one of the developers through the Codeplex connection and got no response. It's beginning to look like Facebook development in ASP.NET is at a bit of a standstill which is really unfortunate. That said, we do have the source to this library as well as Facebook.NET so perhaps it's up the to community to grab the reins. I wish I had time the time to do just that but that's not in the cards are this point.

Steve Trefethen

6/24/2008 8:59:33 PM #

I have a question, Is there a way to make an application to only be called from your website? I have an app that sends mini feeds to the user's friends. When the user installs the apps, he can call it from his facebook account via link. My issue is that when the app is being called from the user's facebook account, the web page that is inside the facebook frame just don't look right(too big for the frame). When the app is being called from my website the page is not being pulled into the facebook frame and it looks perfect. How can I fix this issue, is there  a way to fix it? If I have to create a specific page for each of the mentioned calling methods, how can I identify where the app is being called from from my website or from the user's facebook account link of my installed app.


Thanks

Oleg

6/26/2008 8:29:08 AM #

hi
i just want to ask can i login to my site using facebook account (name and password)
thanks

miro

6/26/2008 8:43:29 PM #

Oleg & miro,
  For support on Facebook development I'd highly recommend the Facebook developer support forums. That said I'm not really sure I understand either question being asked.

Steve Trefethen

6/28/2008 3:02:22 AM #

Steve,

You blog was the starting point for me when I first got into Facebook development.  The information you have here is GREAT!

At the same time I've been reading Applying Domain-Driven Design and Patterns by Jimmy Nilsson.  And have also purchased, and use Martin Folwer's book on Patterns in Enterprise Application Architecture.  In addition, I've worked a bit with Castle's ActiveRecord & Monorail.  

That brings me to how I've changed my approach to developing Web Application and see a lot of value in the Model View Controller pattern.  

I therefore built a Add-on for the Facebook Developer Toolkit that adds support for ASP.NET MVC Preview (unfortunately not Castle Monorail although I may add it later)

It's a little lean on documentation but I'd love for you to check it out and let me know what you think...

http://www.codeplex.com/FacebookMvcAddon

Thank for the great info! Peter

Peter Corcoran

6/29/2008 6:24:08 AM #

Steve,

thanks for your answer but I still can't find what I am searching about which is getting information from facebook without entering the login page just sending request containing e-mail and password and get a responce , can that be ?

I worked in the steps put i stopped at the exception saying "invalid parameter " when i call the function CreateSession(AuthToken) !!!!!!!!!!
so I need to know what to do with that exception

miro

6/29/2008 1:59:11 PM #

miro,
  I don't understand what it is that you're trying to do. It sounds like you're attempting to circumvent the login page and running into trouble which doesn't surprise me.

Good luck.

Steve Trefethen

7/1/2008 7:55:51 AM #

How can i know if a user add my application to his application.
How can i update feeds, like user has scored the heighest score etc...

eMan

7/28/2008 1:58:37 PM #

how to use multiselector friends list in ASP .NET using c#?

please hel me

vijay

8/8/2008 8:14:03 AM #

Thanks for sharing, this helps me a lot.

Spyko

9/17/2008 10:32:58 AM #

Hi Steve,
Its been great challenge to work on face book API. I am trying to send a mail through Notification.SendEmail method. The method returns NULL with no error message/exception as per the documentation this method returns coma seperated mailids to which the mail is sent successfully.

Can you please help me to resolve this issue? Its very urgent.

Thanks a lot in advance.
Phani...

Phani

9/18/2008 6:38:44 AM #

Hi steve,

Iam new bie to facebook developement...
when i get the assignment on last month, iam used the starter kit. it is very helpful for me.   but after facebook turned to 'NEW' my application running in trouble. so i downloaded new toolkit from codeplex ver.2, there are lot of changes in the codebase, so can you please update the starter kit ? it will really helpful for the new developers like me. Thanks.

Pravi

10/3/2008 7:54:57 AM #

hi have just starter developing facebook app, i am newbie have tried to use friendlist control to show list of friends in my source file after ispostback i used frindlist.friends = fb.getfriends but i can not see any of my firnends when the app start any idea

happy

11/25/2009 10:11:49 PM #

I read your file its good to make application.
I am new in this .
Can you resolve a query of mine.

               I want to add allow window before new user to enter in the application.
unless user click on allow he wont be able to enter in to the application.
if user is member he can get entry in the application so here that allow window need not be display. How to create a session key, for adding the page.

Please reply me soon............
Thanks & Regards

Sadhana India

12/15/2009 5:42:46 AM #

Hi

    I am new to facebook application, now i created a application in facebook, after that created a website in visual studio 2005, my task is to send a message or update status in facebook user. I downloaded the .Net Facebook API Client Alpha v2.0 but this starter kit is not responding well, it means that, when ever I opened the Facebook.VisualStudio.exe it is open a starter kit asking to enter api key and secret key after giving values i press continue after that it is not populating why ......


Please tell me what wrong i am doing

Thanks & Regards

krishna India

12/17/2009 1:14:13 AM #

Hi Steve,
Yes its a nice post. Since the documentation for asp.net not so good yet thats why your tricks will help us a lot. Thanks for sharing.

Shawpnendu Bangladesh

12/28/2009 1:24:59 AM #

Hi,

     I am developing windows application in c#.net i.e uploading photos and videos to the facebook using face book api's.  I am able to loging, getting albums but i need to upload photos and videos to the face book. Please help me to come across with this.  I am using
         " facebookService1.CreateAlbum("name","image path","test");"
can you suggest me how to resolve this.

Thanks,
Jeevan

yjeevanrao India

12/29/2009 10:51:21 PM #

Hi steve,

     I am new to facebook application, now i am developing application using c#.net technology for desktop application to upload photos to the facebook.  I am able to create album using facebook api but not able to upload the photos to the it asking for aid(album id).  Can you please tell me how to get the album id.

Thanks & Regards,
Jeevan.

yjeevanrao India

1/14/2010 2:59:23 AM #

Dear Sir,

I have developed a desktop application using C# .Net. Now I want to make a Facebook app out of this with similar functionality. How could I best do this in the shortest possible time.

I would eagerly for your kind suggestions and reply.

Best Regards,
Jagmohan Singh

Jagmohan Singh India

1/15/2010 2:57:47 AM #

Steve,
A very good article. what's ur consultation fee?

Ranjith India

2/22/2010 3:05:51 AM #

Hi,

I am using Notifications.SendEmail(userId, "text","msg",""). But it returns null. How to proceed?

Thanks in advance

test India

2/23/2010 12:34:20 AM #

Great article and great help to beginners like me thanks very much

vishal India

3/1/2010 1:54:53 PM #

Thanks Steve!
Tried lots of different facebook start kits /tutorials in last 4 days, your article & startkit v2.1 got us up an running in minutes!!

vype United Kingdom

3/26/2010 6:12:03 AM #

excellent - i used your sample app and i was up and running building a facebook app for my compay in no time.
ill keep you posted with my next facebook venture

mark emerson United Kingdom

5/12/2011 10:11:03 AM #

hi
i just want to ask can i login to my site using facebook account (name and password)
thanks

Ravi Kumar Gupta India

5/18/2011 7:55:48 AM #

hello sir,,
i want to list of my pages which are added on my profile..
is it possible to get all pages list using your code..

i m waiting for answer..
its very important for me .
i m wasting my seven days..

thanks in advance

umar India

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading