Use facebook.API in web service

Mar 11, 2009 at 4:46 PM
I'm trying to use the Facebook API in a web service to send notifications on user actions.

My application (IFrame based) is using jquery to talk to a webservice for updating information and when certain tasks is completed, I need to send a notification to Facebook.

I'm using C# and would like to know how to achieve the following (as is possible in code-behind pages) in my web service:

Master.API.notifications.send(member.FacebookId, "notification message")

Mar 12, 2009 at 3:17 AM
Just create a new API object, set your APIKey and Secret, then do the call itself. You may need to call ConnectToFacbook() first (or whatever that method is, don't have the code in front of me right now).
Mar 12, 2009 at 12:11 PM
I have set the following:

api.ApplicationKey = ConfigurationManager.AppSettings["APIKey"];
api.Secret = ConfigurationManager.AppSettings["Secret"];

But the description of the ConnectToFacebook() method (which is a void) says:
"Displays an integrated browser to allow the user to log on to the Facebook website".

Will this actually authenticate the api that I can then call "notifications.send(....);" ?
Mar 12, 2009 at 4:07 PM
I managed to get this working.... I saved the session key to my page and when posting to my web services, just sent the session key together with my form elements as a hidden field. I could then use the session key after processing the information in the web service to send the notification back to facebook.

Code I used:

facebook.Components.FacebookService fs = new facebook.Components.FacebookService();
fs.ApplicationKey = ConfigurationManager.AppSettings["APIKey"];
fs.Secret = ConfigurationManager.AppSettings["Secret"];
string sessionKey = dict["facebook_session_key"];
fs.SessionKey = sessionKey;
fs.uid = long.Parse(member.FacebookId);
fs.notifications.send(member.FacebookId, "notification message");
Jun 3, 2009 at 8:14 PM

I can't make api.ConnectToFacebook() for a web app, when I call it, nothing happens... how am I supposed to connect and get a session key with a web app?

Jun 3, 2009 at 10:48 PM

What are you trying to accomplish?

Are you writing a facebook canvas web application?  If so, you should use one of the base pages or master pages from facebook.web.  This will handle the handshake for you.  And if you set requireLogin to true, then the session will be created.  if it is not a canvas page, then you should probably be using facebook connect to handle the handshake and session creation.

I am hoping to create some doc around the initial steps in the next day or 2.

Jun 4, 2009 at 2:23 PM

Thank you, I will look into the Facebook Connect option I think.