Implement Streams.publish - it's now fairly easy to publish "actions" to
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 29 Apr 2009 19:54:43 +0000 (15:54 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 29 Apr 2009 19:54:43 +0000 (15:54 -0400)
facebook triggered by horde interactions...like uploading new images to an ansel
gallery, or making a new news article in jonah etc...

framework/Service_Facebook/lib/Horde/Service/Facebook/Streams.php

index 7fa1c0b..9e3d583 100644 (file)
@@ -29,7 +29,7 @@ class Horde_Service_Facebook_Streams extends Horde_Service_Facebook_Base
                  $limit = '', $filterKey = '')
     {
         if (empty($viewerId) && !$session_key = $this->_facebook->auth->getSessionKey()) {
-            throw new Horde_Service_Facebook_Exception('users.hasAppPermission requires either a uid or a session_key',
+            throw new Horde_Service_Facebook_Exception('Streams.publish requires either a uid or a session_key',
                 Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
         }
         $params = array('viewer_id' => $viewerId,
@@ -75,9 +75,27 @@ class Horde_Service_Facebook_Streams extends Horde_Service_Facebook_Base
      * @param string $action_links  Array of action links.
      * @param string $target_id     The id of user/page you are publishing to.
      */
-    function publish($message = '', $attachment = '', $action_links = '', $target_id = '')
+    function publish($message = '', $attachment = '', $action_links = '', $target_id = '', $uid = '')
     {
+        if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('Streams.publish requires either a uid or a session_key',
+                Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
+        }
+
+        $params = array('message' => $message,
+                        'action_links' => $action_links,
+                        'target_id' => $target_id);
+        if (!empty($uid)) {
+            $params['uid'] = $uid;
+        }
+        if (!empty($session_key)) {
+            $params['session_key'] = $session_key;
+        }
+        if (!empty($attachment)) {
+            $params['attachment'] = json_encode($attachment);
+        }
 
+        return $this->_facebook->callMethod('Stream.publish', $params);
     }
 
     /**