Copyright 2009-2014 Horde LLC (http://www.horde.org/)
/** * Uploads a video. * * @param array $params The parameter array. * - file: (string) A local path to the file to upload. * DEFAULT: none REQUIRED * - caption: (string) The photo caption. * DEFAULT: None. * - uid: (string) The Facebook UID of where to post the video to. Normally * a user id. * DEFAULT: None (Will upload on behalf of the current user). * @return array An array of user objects */ public function upload(array $params = array()) { // Requires either a owner_uid or a session_key if (!$this->_facebook->auth->getSessionKey()) { throw new Horde_Service_Facebook_Exception('photos.addTag requires either a uid or a session_key', Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); } if (empty($params['file'])) { throw new InvalidArgumentException('Missing required file parameter.'); } // Build the data to send. $data = array('message' => empty($params['caption']) ? '' : $params['caption']); $uid = empty($params['uid']) ? 'me/videos' : $params['uid'] . '/videos'; $request = new Horde_Service_Facebook_Request_Graph($this->_facebook, $uid); return $request->upload(array('params' => $data, 'file' => $params['file'])); }
/** * Call the Facebook Graph API. * * @param string $method The endpoint (method) to call. * @param array $params An array of parameters to pass along with the call. * @param array $options Additional request options: * - request: (string) 'POST', 'GET', 'DELETE' etc.. * * @return mixed The results of the API call. */ public function callGraphApi($method = '', array $params = array(), array $options = array()) { $request = new Horde_Service_Facebook_Request_Graph($this, $method, $params, $options); return $request->run(); }
/** * Uploads a photo. * * @param array $params The parameter array. * - file: (string) A local path to the file to upload. * DEFAULT: None, but either 'file' or 'url' is required. * - url: (string) A URL to an image to upload. * DEFAULT: None, but either 'file' or 'url' is required. * - aid: (string) The album id. * DEFAULT: None (Will upload to the application's album). * - caption: (string) The photo caption. * DEFAULT: None. * - place: (string) A Facebook UID of the place the photo was taken near. * DEFAULT: None. * - uid: (string) The Facebook UID of the user we are uploading on behalf * of. * DEFAULT: None (Will upload on behalf of the current user). * @return array An array of user objects */ public function upload(array $params = array()) { // Requires either a owner_uid or a session_key if (!$this->_facebook->auth->getSessionKey()) { throw new Horde_Service_Facebook_Exception('photos.addTag requires either a uid or a session_key', Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); } // Defaults $params = array_merge(array('caption' => '', 'aid' => '', 'place' => ''), $params); // Build the data to send. $data = array('message' => $params['caption'], 'place' => $params['place']); // Uploading to the application gallery or other? if (!empty($params['aid'])) { $uid = $params['aid'] . '/photos'; } else { $uid = empty($params['uid']) ? 'me/photos' : $params['uid'] . '/photos'; } // Uploading image or providing URL? if (!empty($params['file'])) { $request = new Horde_Service_Facebook_Request_Graph($this->_facebook, $uid); return $request->upload(array('params' => $data, 'file' => $params['file'])); } elseif (!empty($params['url'])) { $data['url'] = $params['url']; } return $this->_facebook->callGraphApi($uid, $data, array('request' => 'POST')); }