コード例 #1
0
ファイル: TwitterOAuth.php プロジェクト: keisuke2/twitter_bot
 /**
  * Format and sign an OAuth / API request
  *
  * @param string $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  * @throws TwitterOAuthException
  */
 private function oAuthRequest($url, $method, array $parameters)
 {
     $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters);
     if (array_key_exists('oauth_callback', $parameters)) {
         // Twitter doesn't like oauth_callback as a parameter.
         unset($parameters['oauth_callback']);
     }
     if ($this->bearer === null) {
         $request->signRequest($this->signatureMethod, $this->consumer, $this->token);
         $authorization = $request->toHeader();
     } else {
         $authorization = 'Authorization: Bearer ' . $this->bearer;
     }
     return $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters);
 }
コード例 #2
0
 /**
  * Format and sign an OAuth / API request
  *
  * @param string $url
  * @param string $method
  * @param array  $parameters
  * @param bool   $multipart
  *
  * @return string
  * @throws TwitterOAuthException
  */
 private function oAuthRequest($url, $method, array $parameters, $multipart = false)
 {
     $signature_parameters = array();
     // When making a multipart request, use only oauth_* -keys for signature
     foreach ($parameters as $key => $value) {
         if ($multipart && strpos($key, 'oauth_') !== 0) {
             continue;
         }
         $signature_parameters[$key] = $value;
     }
     $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $signature_parameters);
     if (array_key_exists('oauth_callback', $parameters)) {
         // Twitter doesn't like oauth_callback as a parameter.
         unset($parameters['oauth_callback']);
     }
     if ($this->bearer === null) {
         $request->signRequest($this->signatureMethod, $this->consumer, $this->token);
         $authorization = $request->toHeader();
     } else {
         $authorization = 'Authorization: Bearer ' . $this->bearer;
     }
     return $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters, $multipart);
 }