thoughtlabs

Facebook API: Undocumented Cookie Management REST APIs

Written by Cappy Popp  ()
on February 15, 2008 ·

Facebook-Developer

The Facebook API does have a way to set and get cookies, but it is in beta so is not currently part of the FB PHP libraries. I found it out by searching through forums, by trial-and-error, and on the FB Beta docs page. There are 2 functions available:

  data.getCookies( user_id, cookie_name );
  data.setCookie( user_id, cookie_name, cookie_value, expires, path );

To use these functions from PHP I simply wrapped them in functions that call the RESTful APIs correctly:

// to get cookies for a given user (optionally by name):
function get_cookie($uid, $name=null) {
  global $facebook;
  return $facebook->api_client->call_method('data.getCookies', array('uid' => $uid, 'name' => $name) );
}

// to set a cookie for a given user:
function set_cookie($uid, $name, $value, $expires=null, $path=null){
  global $facebook;
  return $facebook->api_client->call_method('data.setCookie', array('uid' => $uid, 'name' => $name,
    'value' => $value, 'expires' => $expires, 'path' => $path) );
}

Topics: Programming

Sign up for our Fresh Thoughts Newsletter

Follow us:

Get Articles via Email

Enjoy this article? Don't forget to share.