示例#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
文件: twipic.php 项目: book000/mcmn
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;
}
示例#3
0
文件: OAuth.php 项目: shupp/openid
 /**
  * Fetch an OAuth access token
  *
  * Requires an request_token to be present in self::$values
  *
  * @param string $consumerKey    OAuth consumer application key
  * @param string $consumerSecret OAuth consumer secret key
  * @param string $url            Access token url
  * @param array  $params         Paramters to include in the request
  *                               for the access token
  * @param string $method         HTTP Method to use
  *
  * @return array Key => Value array of token and token secret
  *
  * @throws OpenID_Exception     On no request_token in response message
  * @throws HTTP_OAuth_Exception On issue with getting the request token
  *
  * @see http://step2.googlecode.com/svn/spec/openid_oauth_extension/latest/openid_oauth_extension.html
  */
 public function getAccessToken($consumerKey, $consumerSecret, $url, array $params = array(), $method = 'GET')
 {
     $requestToken = $this->get('request_token');
     if ($requestToken === null) {
         throw new OpenID_Exception('No oauth request token in OpenID message');
     }
     $consumer = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret);
     $consumer->setToken($requestToken);
     // Token secret is blank per spec
     $consumer->setTokenSecret('');
     // Blank verifier
     $consumer->getAccessToken($url, '', $params, $method);
     return array('oauth_token' => $consumer->getToken(), 'oauth_token_secret' => $consumer->getTokenSecret());
 }
$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();
ob_start();
while ($json = fgets($stream)) {
    $output = $json;
//    request manually.)

$response = $consumer->sendRequest("http://".$domain."/oauth/access_token", array("oauth_verifier" => $oauth_verifier), "GET");
$data     = $response->getDataFromBody();


if (empty($data['oauth_token']) || empty($data['oauth_token_secret'])) {
    throw new HTTP_OAuth_Consumer_Exception_InvalidResponse(
       'Failed getting token and token secret from response', $response
    );
}

print_r($data);

$consumer->setToken($data['oauth_token']);
$consumer->setTokenSecret($data['oauth_token_secret']);


// 5. Save credentials to config file
$handle = @fopen("visualplatform.config.php", "w");
$_conf = array(
                'domain'       => $data['domain'],
                'user_id'      => $data['user_id'],
                'key'          => $consumer->getKey(),
                'secret'       => $consumer->getSecret(),
                'token'        => $consumer->getToken(),
                'token_secret' => $consumer->getTokenSecret()
        );
fwrite($handle, '<? $visualplatform_config = unserialize(\'' . serialize($_conf) . '\'); ?>');
fclose($handle);