Author: Chuck Hagenbuch (chuck@horde.org)
Example #1
0
 /**
  * Send a POST request to the twitter API. Purposely do not cache results
  * from these since POST requests alter data on the server.
  *
  * @see self::get
  */
 public function post($url, array $params = array())
 {
     $request = new Horde_Oauth_Request($url, $params);
     $request->sign($this->_twitter->auth->oauth->signatureMethod, $this->_twitter->auth->oauth, $this->_twitter->auth->getAccessToken($this->_request));
     $url = $url instanceof Horde_Url ? $url : new Horde_Url($url);
     try {
         $response = $this->_twitter->getHttpClient()->post($url->setRaw(true), $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API')));
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Service_Twitter_Exception($e);
     }
     if ($response->code >= 400 && $response->code <= 500) {
         throw new Horde_Service_Twitter_Exception($response->getBody());
     }
     return $response->getBody();
 }
Example #2
0
 /**
  * Obtain an access token from a request token
  *
  * @param Horde_Oauth_Token $token Open auth token containing the oauth_token
  *                                 returned from provider after authorization
  *                                 and the token secret returned with the
  *                                 original request token.
  * @param array $params           Any additional parameters for this request
  *
  * @return unknown_type
  */
 public function getAccessToken($token, $params = array())
 {
     $params['oauth_consumer_key'] = $this->key;
     $params['oauth_token'] = $token->key;
     $request = new Horde_Oauth_Request($this->accessTokenUrl, $params);
     $request->sign($this->signatureMethod, $this, $token);
     $client = new Horde_Http_Client();
     try {
         $response = $client->post($this->accessTokenUrl, $request->buildHttpQuery());
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Oauth_Exception($e->getMessage());
     }
     return Horde_Oauth_Token::fromString($response->getBody());
 }