This project is read-only.

Updating profile outside of session/request context

Nov 26, 2007 at 1:46 PM
Hi Everyone,

I'm saving the facebook ID and session key for my users, and I want to update their profile when certain events occur. I want to do this without a request from facebook, when the user isn't logged in. I've seen discussions of this and I know the facebook API supports it...

Does anyone have a code sample of this for Facebook.NET? I'm not clear on what objects/properties I need to create/set in order to accomplish this. I've successfully updated the profile from within a page request, I just don't know how to initiate the connection to facebook outside of the request context.

Thanks in advance,
Dec 2, 2007 at 10:02 PM
Ok, I answered my own question. It's simple enough. I suppose half the fun of open-source freeware stuff is figuring how how to do everything with no documentation.

First you need to have stored the facebook ID and infinite session key for the user whose information you want to update. The application key and secret are already in web.config, if you're set up the same way as the example project. So here's the code:

using Facebook.Service;
using Facebook.Web;
using Facebook.Web.Configuration;
namespace MyNamespace.Facebook
   public class Utils
      public static void UpdateProfile(string facebookID, string facebookSession)
          FacebookSection section = 
          FacebookService service = new FacebookService(
          string profileFbml = BuildProfileFbml(facebookID);
          service.Profile.SetFbml(profileFbml, null);
          string titleFbml = " is testing stuff...";
          string bodyFbml = "test";
          service.Feed.PublishMiniFeedStory(titleFbml, bodyFbml, null);