facebook.batch

Aug 10, 2009 at 10:48 PM

Hello all,

Has anyone got an example of how the batch API works on this toolkit. Doesnt seem to be any documentation or examples and I cant seem to get it working either.

I seem to get a object not set to reference error when I chain multiple API calls. Would love to use this to reduce the latency of processing.

 

Thanks

Nov 23, 2009 at 4:22 AM

Hi kirby,

I've been playing with the 3.0 version of the toolkit in an ASP.NET MVC project and the following snippet seems to be working for me. I haven't seen any samples around either.

Hope this helps.

// Setup a connect session 
var oConnectSession = new Facebook.Session.ConnectSession(APIKEY, SECRET);

// Session key is taken from cookie (as this is for an iframe app, 
// however if offline access is enabled you might get this a database where
// you store the infinite session key.
// Note: This is only required as the Users.HasAppPermission call requests 
//       a user session.
oConnectSession.SessionKey = this.Request.Cookies[string.Format("{0}_session_key", APIKEY)].Value;
oConnectSession.Login();

// Create API using session from connect session
// Make sure the application in use has a facebook connect URL
Facebook.Rest.Api oApi = new Facebook.Rest.Api(oConnectSession);

// Ensure tasks are queued for a single request
oApi.Batch.BeginBatch();

// queue tasks
oApi.Users.HasAppPermission(Enums.ExtendedPermissions.offline_access);
oApi.Users.HasAppPermission(Enums.ExtendedPermissions.email);
oApi.Users.HasAppPermission(Enums.ExtendedPermissions.publish_stream);
oApi.Users.HasAppPermission(Enums.ExtendedPermissions.read_stream);

// execute batch and return list of results
IList<object> oBatchResult = oApi.Batch.ExecuteBatch();

// Assign list items to appropriate variables
// items are returned in the same order they are requested
ViewData["fb_offline_access"] = ((BooleanResponse)oBatchResult[0]).TypedValue;
ViewData["fb_email"] =          ((BooleanResponse)oBatchResult[1]).TypedValue;
ViewData["fb_publish_stream"] = ((BooleanResponse)oBatchResult[2]).TypedValue;
ViewData["fb_read_stream"] =    ((BooleanResponse)oBatchResult[3]).TypedValue;

// Logout of the session 
oConnectSession.Logout();

 

 

Oct 25, 2010 at 8:41 AM

Thanks for posting your code. I couldn't find any samples until yours.