I've been toying with the Facebook Platform the the past few days and am impressed by it thus far, minus the lack of documentation and usage examples. I created a base class to extend applications from in order to get a feel for how application are structured. It is based after the only coherent piece of documentation I have been able to find, here. I will publish my code soon; in the mean time, here is an example:
class FacebookApplication {
...
function get_friends_with_app_installed() {
$fql = "SELECT uid from user where uid in (SELECT uid2 FROM friend WHERE uid1=".$this->get_client_id().") and is_app_user=1;";
return $this->get_client()->api_client->fql_query( $fql );
}
}
class LookMiiUpFacebookApp extends FacebookApplication {
...
function splash() {
echo "lookmiiup splash";
print_r( $this->get_friends_with_app_installed() );
}
function set_info() {
$wii = strip_tags($_REQUEST["wii"]);
$facebook = $this->get_client();
$user = $this->get_client_id();
$facebook->api_client->profile_setFBML("Wii Number: $wii", $user);
$facebook->api_client->feed_publishActionOfUser( "got a new Wii number", "$wi
i" );
echo "wii: $wii";
}
function handle_request() {
static $allowed_methods = array(
"set_info"
);
if( in_array( $method, $allowed_methods ) ) {
$params = array();
call_user_func_array( array( $this, $method ), $params );
} else {
parent::handle_request();
}
}
}
$fbapp = new LookMiiUpFacebookApp( $appapikey, $appsecret, $appcallbackurl );
$fbapp->require_login();
$fbapp->require_installation();
$fbapp->handle_request();
The added value is the ability to more intuitively (in my opinion, anyway) create an application that requires login/installation and setup the handler methods. I plan to use it, with Smarty for FBML generation, to integrate LookMiiUp into Facebook.
0 comments:
Post a Comment