FacebookNET Sessionless Updates

by Jim Dec 02, 2007 2:48 PM

I'm experimenting with the facebook API lately using Nikhil Kothari's Facebook.NET. The first thing I've had to do that wasn't entirely obvious from the example code was update the profile outside the context of a request.

This is a common scenario, I think - sending messages or updating the profile in response to events that happen when nobody is actually accessing the application.

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 = 
             (FacebookSection)ConfigurationManager.GetSection("facebook");
           
          FacebookService service = new FacebookService(
             section.Applications[0].ApiKey, 
             section.Applications[0].Secret, 
             facebookSession, 
             facebookID
             );


          string profileFbml = BuildProfileFbml(facebookID);

          service.Profile.SetFbml(profileFbml, null);

          string titleFbml = " is testing stuff...";

          string bodyFbml = "test";

          service.Feed.PublishMiniFeedStory(titleFbml, bodyFbml, null);
       }

Tags:

Add comment


(Shows Gravatar icon; will not be displayed)

  Country flag
Click to change captcha
biuquote
  • Comment
  • Preview
Loading