From c9593bf01b1b2628830cf4ad9099f0a11c67995f Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Tue, 17 Feb 2009 20:40:55 -0500 Subject: [PATCH] Try to keep the example doc in-line with changes as I work... More camelCase method names.. --- .../Service_Facebook/doc/facebook_example.php | 50 +++++++++++++++++++--- .../lib/Horde/Service/Facebook.php | 4 +- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/framework/Service_Facebook/doc/facebook_example.php b/framework/Service_Facebook/doc/facebook_example.php index a130f0dab..631d10c6d 100644 --- a/framework/Service_Facebook/doc/facebook_example.php +++ b/framework/Service_Facebook/doc/facebook_example.php @@ -1,19 +1,39 @@ alert("testing callback:' . $url . '");'; + exit; +} + define('HORDE_BASE', '/private/var/www/html/horde'); require_once HORDE_BASE . '/lib/base.php'; $appapikey = 'xxx'; //CHANGE THIS -$appsecret = 'xxx'; //CHANGE THIS +$appsecret = 'xxx'; //CHANGE THIS + +// Horde_Service_Facebook *requires* an http_client, http_request objects +// it can optionally use a callback function to handle login redirects +$context = array('http_client' => new Horde_Http_Client(), + 'http_request' => new Horde_Controller_Request_Http(),); + //'login_redirect_callback' => 'testFBCallback'); -$facebook = new Horde_Service_Facebook($appapikey, $appsecret, null, false); +// Create the facebook object and make sure we have an active, authenticated +// session. +$facebook = new Horde_Service_Facebook($appapikey, $appsecret, $context); $user_id = $facebook->require_login(); -// Use a fql query to get some friend info + +/** Use a FQL query to get some friend info **/ $result = $facebook->fql_query('SELECT name, status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ' . $user_id . ')'); var_dump($result); -// Similar can be done as so using individual api calls... -// $friends = $facebook->friends_get(); +/** Similar can be done as so using individual api calls...but takes a *long* time **/ +//$friends = $facebook->friends_get(); // foreach ($friends as $friend) { // $personArray = $facebook->users_getInfo($friend, 'name'); // $person[] = $personArray[0]; @@ -24,5 +44,21 @@ var_dump($result); // } -// Get a list of new notifications: -var_dump($facebook->notifications_get()); \ No newline at end of file +/** Calling code that requires extended permissions **/ +try { + $facebook->users_setStatus('is testing my facebook code...again.'); +} catch (Horde_Service_Facebook_Exception $e) { + // Check that we failed because of insufficient app permissions. + // then redirect if needed... +} + +/** Batch mode. **/ +// When calling in batch mode, you must assign the results of the method calls +// as a reference so when run() is called, you still have a handle to the +// results. +$facebook->batchBegin(); +$notifications = &$facebook->notifications_get(); +$friends = &$facebook->friends_get(); +$facebook->batchEnd(); +var_dump($friends); +var_dump($notifications); \ No newline at end of file diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook.php b/framework/Service_Facebook/lib/Horde/Service/Facebook.php index be5bd95eb..7d5001ff8 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook.php @@ -552,7 +552,7 @@ class Horde_Service_Facebook /** * Start a batch operation. */ - public function begin_batch() + public function batchBegin() { if ($this->_batchRequest !== null) { $code = Horde_Service_Facebook_ErrorCodes::API_EC_BATCH_ALREADY_STARTED; @@ -566,7 +566,7 @@ class Horde_Service_Facebook /** * End current batch operation */ - public function end_batch() + public function batchEnd() { if ($this->_batchRequest === null) { $code = Horde_Service_Facebook_ErrorCodes::API_EC_BATCH_NOT_STARTED; -- 2.11.0