Try to keep the example doc in-line with changes as I work...
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 18 Feb 2009 01:40:55 +0000 (20:40 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 18 Feb 2009 01:40:55 +0000 (20:40 -0500)
More camelCase method names..

framework/Service_Facebook/doc/facebook_example.php
framework/Service_Facebook/lib/Horde/Service/Facebook.php

index a130f0d..631d10c 100644 (file)
@@ -1,19 +1,39 @@
 <?php
+/**
+ * A test callback function for login redirects.
+ * @param $url
+ * @return unknown_type
+ */
+function testFBCallback($url)
+{
+    echo '<script type="text/javascript">alert("testing callback:' . $url . '");</script>';
+    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
index be5bd95..7d5001f 100644 (file)
@@ -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;