Пример #1
0
    /**
     *
     * @param TW2MV_Configure
     * @since version 2.1.0
     */
    public function __construct($config)
    {
        parent::__construct($config);

        try {

            // OAuthリクエスト
            $consumer_request = new HTTP_OAuth_Consumer_Request();
            $consumer_request->accept($this->http);

            $this->oauth = new HTTP_OAuth_Consumer($this->config->twitter_oauth_consumer_key, $this->config->twitter_oauth_consumer_secret);
            $this->oauth->accept($consumer_request);

            if (empty($this->config->twitter_oauth_access_token) || empty($this->config->twitter_oauth_access_token_secret)) {

                // Access Tokenを取得
                $this->_getAccessToken();

            }

            // トークンをセット
            $this->oauth->setToken($this->config->twitter_oauth_access_token);
            $this->oauth->setTokenSecret($this->config->twitter_oauth_access_token_secret);

        } catch (Exception $e) {

            debug($e->getMessage());

        }

    }
Пример #2
0
function twipic($f, $a, $b, $m)
{
    $twitpic_api = "";
    $consumer_key = "";
    $consumer_secret = "";
    $access_token = $a;
    $access_token_secret = $b;
    $imagepath = $f;
    $message = $me;
    $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
    $consumer->setToken($access_token);
    $consumer->setTokenSecret($access_token_secret);
    $http_request = new HTTP_Request2();
    $http_request->setConfig('ssl_verify_peer', false);
    $consumer_request = new HTTP_OAuth_Consumer_Request();
    $consumer_request->accept($http_request);
    $consumer->accept($consumer_request);
    $resp = $consumer->sendRequest('https://api.twitter.com/1.1/account/verify_credentials.json', array(), HTTP_Request2::METHOD_GET);
    $headers = $consumer->getLastRequest()->getHeaders();
    $http_request->setHeader('X-Auth-Service-Provider', 'https://api.twitter.com/1.1/account/verify_credentials.json');
    $http_request->setHeader('X-Verify-Credentials-Authorization', $headers['authorization']);
    $http_request->setUrl('http://api.twitpic.com/2/upload.json');
    $http_request->setMethod(HTTP_Request2::METHOD_POST);
    $http_request->addPostParameter('key', $twitpic_api);
    $http_request->addPostParameter('message', $m);
    $http_request->addUpload('media', $imagepath);
    $resp = $http_request->send();
    $body = $resp->getBody();
    $body = json_decode($body, true);
    return $body;
}
header("Content-type: text/event-stream; charset=utf-8");
header("Transfer-encoding: chunked");
$_TARGET_URL = "https://userstream.twitter.com/2/user.json";
$consumer_key = $consumer_secret = $access_token = $access_token_secret = $time = time();
$oauth_nonce = md5($time . rand());
include_once 'HTTP/OAuth/Consumer.php';
$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
//認証用
$signature = HTTP_OAuth_Signature::factory($consumer->getSignatureMethod());
//signature作成用
//HTTPS接続の設定
$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);
$consumer_request = new HTTP_OAuth_Consumer_Request();
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);
//Tokenの設定
$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);
//signature用の文字列設定
$param = array("oauth_consumer_key" => $consumer_key, "oauth_nonce" => $oauth_nonce, "oauth_signature_method" => $consumer->getSignatureMethod(), "oauth_timestamp" => $time, "oauth_token" => $access_token, "oauth_version" => "1.0");
//sigunature作成
$oauth_signature = urlencode($signature->build("GET", $_TARGET_URL, $param, $consumer_secret, $access_token_secret));
//echo 'Authorization: OAuth oauth_consumer_key="' . $consumer_key .'", oauth_nonce="'. $oauth_nonce .'", oauth_signature="' . $oauth_signature .'", oauth_signature_method="' . $consumer->getSignatureMethod() .'", oauth_timestamp="' . $time .'", oauth_token="' . $access_token .'", oauth_version="1.0"';
//HTTP通信ヘッダの作成
$options = array('http' => array('method' => "GET", 'header' => 'Authorization: OAuth oauth_consumer_key="' . $consumer_key . '", oauth_nonce="' . $oauth_nonce . '", oauth_signature="' . $oauth_signature . '", oauth_signature_method="' . $consumer->getSignatureMethod() . '", oauth_timestamp="' . $time . '", oauth_token="' . $access_token . '", oauth_version="1.0"', "Content-type: application/x-www-form-urlencoded\r\n"));
//通信と出力
//JSONに変換可能だったもののみ、出力を行う。
$context = stream_context_create($options);
$stream = fopen($_TARGET_URL, 'r', false, $context);
ob_end_flush();
Пример #4
0
 /**
  * @expectedException HTTP_OAuth_Exception
  */
 public function testAcceptNotSupported()
 {
     $consumer = new HTTP_OAuth_Consumer('key', 'secret');
     $consumer->accept(new stdClass());
 }
Пример #5
0
 /**
  * Sends a request using OAuth instead of basic auth
  * 
  * @param string $uri    The full URI of the endpoint
  * @param string $method GET or POST
  * @param array  $params Array of additional parameter
  * @param array  $files  Array of files to upload
  * 
  * @throws Services_Twitter_Exception on failure
  * @return HTTP_Request2_Response
  * @see prepareRequest()
  */
 protected function sendOAuthRequest($uri, $method, $params, $files)
 {
     include_once 'HTTP/OAuth/Consumer/Request.php';
     try {
         $request = clone $this->getRequest();
         if ($method == 'POST') {
             foreach ($files as $key => $val) {
                 $request->addUpload($key, $val);
             }
         }
         // Use the same instance of HTTP_Request2
         $consumerRequest = new HTTP_OAuth_Consumer_Request();
         $consumerRequest->accept($request);
         $this->oauth->accept($consumerRequest);
         $response = $this->oauth->sendRequest($uri, $params, $method);
     } catch (HTTP_Request2_Exception $exc) {
         throw new Services_Twitter_Exception($exc->getMessage(), $exc, $uri);
     }
     return $response;
 }