当前位置: 首页>>代码示例>>PHP>>正文


PHP buildAuthorizationHeader函数代码示例

本文整理汇总了PHP中buildAuthorizationHeader函数的典型用法代码示例。如果您正苦于以下问题:PHP buildAuthorizationHeader函数的具体用法?PHP buildAuthorizationHeader怎么用?PHP buildAuthorizationHeader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了buildAuthorizationHeader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: launchTwitter

function launchTwitter($terminoBuscar)
{
    /*from tw.php*/
    $url = "https://api.twitter.com/1.1/users/search.json";
    $query = array('count' => 100, 'q' => urlencode($terminoBuscar), "result_type" => "recent");
    $oauth_access_token = "336107062-3FRWmW9u2WqAD8K2BYkkhRyYPiuElAls5xGSPxHO";
    // original 336107062-3FRWmW9u2WqAD8K2BYkkhRyYPiuElAls5xGSPxHO
    $oauth_access_token_secret = "EYOobKPmD0Ym4f30AEOM0xGjlfnaan1Vt17fkUYuJKOnY";
    // original EYOobKPmD0Ym4f30AEOM0xGjlfnaan1Vt17fkUYuJKOnY
    $consumer_key = "zCYb1EGbavxyFI26TSCYpDVHT";
    //original zCYb1EGbavxyFI26TSCYpDVHT
    $consumer_secret = "limIRUXH0FiFRVcdDpOi6SwAxt3ZZpNvj58P2WVXr5mspF0J7t";
    // original limIRUXH0FiFRVcdDpOi6SwAxt3ZZpNvj58P2WVXr5mspF0J7t
    $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
    $base_params = empty($query) ? $oauth : array_merge($query, $oauth);
    $base_info = buildBaseString($url, 'GET', $base_params);
    $url = empty($query) ? $url : $url . "?" . http_build_query($query);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    $resultTwitter = json_decode($json);
    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/publication/search/results/resultTwitter.json', 'w');
    fwrite($fp, json_encode($resultTwitter));
    fclose($fp);
    /*fin from tw.php */
    //	exec('php search/tw.php '.$terminoBuscar);
    //	exit("End TWITTER ".PHP_EOL);
}
开发者ID:brm-sanabrias,项目名称:nemo,代码行数:34,代码来源:launcher.php

示例2: returnTweet

function returnTweet()
{
    $oauth_access_token = "4802840487-Vez1OhbjdjPQ5A0FWVmJNTNw8uzRFuccjabaL3b";
    $oauth_access_token_secret = "H6X4hZmrsjUDqRV3QlXJgSnCI1z4NvM3TRX8CPzb7PU60";
    $consumer_key = "Zde32xAZZD7qlUT94U0KabyHG";
    $consumer_secret = "J85YV2lzFSOiF5aFi1QhDvNq3UtnQZo1cDi8wwQrWNWTiRaO4K";
    $twitter_timeline = "user_timeline";
    //  create request
    $request = array('screen_name' => 'Weblib', 'count' => '4');
    $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_token' => $oauth_access_token, 'oauth_nonce' => time(), 'oauth_timestamp' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_version' => '1.0');
    //  merge request and oauth to one array
    $oauth = array_merge($oauth, $request);
    //  do some magic
    $base_info = buildBaseString("https://api.twitter.com/1.1/statuses/{$twitter_timeline}.json", 'GET', $oauth);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    //  make request
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => "https://api.twitter.com/1.1/statuses/{$twitter_timeline}.json?" . http_build_query($request), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    return parseTweets(json_decode($json, true));
}
开发者ID:Weblib,项目名称:siteweb,代码行数:26,代码来源:twitter.php

示例3: queryTwitter

function queryTwitter($search)
{
    $url = "https://api.twitter.com/1.1/users/search.json";
    //if($search != "")
    //$search = "#".$search;
    $query = array('count' => 100, 'q' => urlencode($search), "result_type" => "recent");
    $oauth_access_token = "336107062-3FRWmW9u2WqAD8K2BYkkhRyYPiuElAls5xGSPxHO";
    $oauth_access_token_secret = "EYOobKPmD0Ym4f30AEOM0xGjlfnaan1Vt17fkUYuJKOnY";
    $consumer_key = "zCYb1EGbavxyFI26TSCYpDVHT";
    $consumer_secret = "limIRUXH0FiFRVcdDpOi6SwAxt3ZZpNvj58P2WVXr5mspF0J7t";
    $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
    $base_params = empty($query) ? $oauth : array_merge($query, $oauth);
    $base_info = buildBaseString($url, 'GET', $base_params);
    $url = empty($query) ? $url : $url . "?" . http_build_query($query);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    return json_decode($json);
}
开发者ID:brm-sanabrias,项目名称:nemo,代码行数:25,代码来源:tw.php

示例4: twitterRequest

function twitterRequest($method, $requestTokenUrl, $params, $oauthParams, $oauthTokenSecret = "2OW7cq5mQanDUxw49ln6pU8HZorzWF37eu0D18jdn0deh")
{
    $curl = curl_init();
    $sigBaseArray = array();
    $consumerSecret = "vP9ECrfJWxN36xASz9RS2gD2ouyf7thH3yfcbHRkHGrLm2YMJJ";
    foreach ($params as $key => $value) {
        $sigBaseArray[$key] = $value;
    }
    foreach ($oauthParams as $key => $value) {
        $sigBaseArray[$key] = $value;
    }
    $sigBaseArray = array_map("rawurlencode", $sigBaseArray);
    asort($sigBaseArray);
    ksort($sigBaseArray);
    $sigBase = $method . "&" . rawurlencode($requestTokenUrl);
    $sigParamString = urldecode(http_build_query($sigBaseArray, '', '&'));
    $sigBase = $sigBase . "&" . rawurlencode($sigParamString);
    var_dump($sigBase);
    $sigKey = rawurlencode($consumerSecret) . "&" . rawurlencode($oauthTokenSecret);
    $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
    var_dump($oauthSig);
    $oauthParams["oauth_signature"] = $oauthSig;
    var_dump(buildAuthorizationHeader($oauthParams));
    $headers = array("Authorization: " . buildAuthorizationHeader($oauthParams));
    curl_setopt($curl, CURLOPT_URL, $requestTokenUrl);
    curl_setopt_array($curl, array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true));
    if ($method === "POST") {
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
    }
    $resultString = curl_exec($curl);
    curl_close($curl);
    return $resultString;
}
开发者ID:smddzcy,项目名称:ESETGuvenlikOyunu,代码行数:34,代码来源:twitter_return.php

示例5: sendRequest

/**
 * Method for sending a request to Twitter.
 * @param array $oauth the oauth array
 * @param string $baseURI the request URI
 * @return string the response from Twitter
**/
function sendRequest($oauth, $baseURI)
{
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    //create header array and add 'Expect:'
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => true, CURLOPT_URL => $baseURI, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true);
    //don't verify SSL certificate, just do it
    $ch = curl_init();
    //get a channel
    curl_setopt_array($ch, $options);
    //set options
    $response = curl_exec($ch);
    //make the call
    curl_close($ch);
    //hang up
    //print_r($response);
    //exit;
    return $response;
}
开发者ID:Sibzsolutions,项目名称:Savostore,代码行数:24,代码来源:Twitter_OAuth.php

示例6: getTweets

function getTweets($usr, $count, $oauth_access_token, $oauth_access_token_secret, $consumer_key, $consumer_secret)
{
    $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
    //    $oauth_access_token = "7134262-5oEfJM3e9QNcP6eFWnoPY6hkPSJmhqXFCljSsanprg";
    //    $oauth_access_token_secret = "UBluMI03on2cIDgYaaSyuwHeAlG5OpfjVt5ZBUg5SY";
    //    $consumer_key = "fCuoVkS3OviKVxzv9nHhA";
    //    $consumer_secret = "AZAEBg1CO60A2ZYcAI4UDM5yy94sRJPOpHXaCNL9qA";
    $oauth = array('oauth_consumer_key' => $consumer_key, 'screen_name' => $usr, 'count' => $count, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
    $base_info = buildBaseString($url, 'GET', $oauth);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    // Make Requests
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=' . $usr . '&count=' . $count, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    //$twitter_data = json_decode($json);
    return $json;
}
开发者ID:Air-Craft,项目名称:air-craft-www,代码行数:22,代码来源:twitter.php

示例7: postTweet

function postTweet($text)
{
    $tweet = $text;
    $data_array = array('status' => $tweet);
    $postfields = http_build_query($data_array);
    $url = "https://api.twitter.com/1.1/statuses/update.json";
    $oauth_access_token = "";
    $oauth_access_token_secret = "";
    $consumer_key = "";
    $consumer_secret = "";
    $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => rand() . rand(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'status' => $tweet);
    $base_info = buildBaseString($url, 'POST', $oauth);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    $header = array(buildAuthorizationHeader($oauth));
    // Make Requests
    $options = array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postfields, CURLOPT_HEADER => false, CURLOPT_HTTPHEADER => $header, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    return $json;
}
开发者ID:sarahgarcin,项目名称:flux-ecran-papier,代码行数:24,代码来源:index.php

示例8: file_get_contents_curl

function file_get_contents_curl($url, $user = null)
{
    $ch = curl_init($url);
    if ($user) {
        $a = explode(',', $user->access_token);
        $oauth_token = $a[0];
        $oauth_token_secret = $a[1];
        $oauth = array('oauth_consumer_key' => CONSUMER_KEY, 'oauth_nonce' => md5(microtime() . mt_rand()), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_token' => $oauth_token, 'oauth_version' => '1.0');
        $base_info = buildBaseString($url, 'POST', $oauth);
        $composite_key = rawurlencode(CONSUMER_SECRET) . '&' . rawurlencode($oauth_token_secret);
        $oauth['oauth_signature'] = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
        $header = buildAuthorizationHeader($oauth);
        //	debuglog($header);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
    }
    $maxallowed = 64 * 1024;
    $totalread = 0;
    $data = '';
    $callback = function ($ch, $text) use(&$data, &$maxallowed, &$totalread) {
        $data .= $text;
        $count = strlen($text);
        $totalread += $count;
        if ($totalread >= $maxallowed || stristr($data, '</head>')) {
            return 0;
        }
        return $count;
    };
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Tweetshow 2.1)');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_ENCODING, "deflate,gzip");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
    curl_exec($ch);
    curl_close($ch);
    //	debuglog(" total read $totalread, ".strlen($data));
    return $data;
}
开发者ID:Bitcoinsulting,项目名称:yiimp,代码行数:42,代码来源:util.php

示例9: yit_get_tweets

 function yit_get_tweets($oauth_access_token, $oauth_access_token_secret, $consumer_key, $consumer_secret, $limit)
 {
     $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
     $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'count' => $limit, 'oauth_version' => '1.0');
     $base_info = buildBaseString($url, 'GET', $oauth);
     $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
     $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
     $oauth['oauth_signature'] = $oauth_signature;
     $header = array(buildAuthorizationHeader($oauth), 'Expect:');
     $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?count=' . $limit, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
     $feed = curl_init();
     curl_setopt_array($feed, $options);
     $json = curl_exec($feed);
     curl_close($feed);
     return json_decode($json);
 }
开发者ID:allyeastman,项目名称:studio-sapphire,代码行数:16,代码来源:functions-template.php

示例10: tweetAction

 public function tweetAction()
 {
     $general = $this->general();
     function buildBaseString($baseURI, $method, $params)
     {
         $r = array();
         ksort($params);
         foreach ($params as $key => $value) {
             $r[] = "{$key}=" . rawurlencode($value);
         }
         return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
     }
     function buildAuthorizationHeader($oauth)
     {
         $r = 'Authorization: OAuth ';
         $values = array();
         foreach ($oauth as $key => $value) {
             $values[] = "{$key}=\"" . rawurlencode($value) . "\"";
         }
         $r .= implode(', ', $values);
         return $r;
     }
     $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
     $oauth_access_token = $general->getTwitterOauthKey();
     $oauth_access_token_secret = $general->getTwitterOauthSecret();
     $consumer_key = $general->getTwitterKey();
     $consumer_secret = $general->getTwitterSecret();
     $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
     $base_info = buildBaseString($url, 'GET', $oauth);
     $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
     $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
     $oauth['oauth_signature'] = $oauth_signature;
     // Make requests
     $header = array(buildAuthorizationHeader($oauth), 'Expect:');
     $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
     $feed = curl_init();
     curl_setopt_array($feed, $options);
     $json = curl_exec($feed);
     //die(print_r($json));
     curl_close($feed);
     $twitter_data = json_decode($json);
     return $this->render('APPCoreBundle:pages' . $general->getTheme()->getId() . ':tweets.html.twig', array('tweets' => $twitter_data, 'general' => $general));
 }
开发者ID:jul6art,项目名称:vscms,代码行数:43,代码来源:CoreController.php

示例11: getTweets

function getTweets($count)
{
    $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
    $oauth_access_token = "210608671-X9bfQpwThRXm1ODQ6kkODb7gQBGotJHAR5sEmjhR";
    $oauth_access_token_secret = "01OjsWkfsOsZSCqRyiv9trJ7WbeJorGFrUjMKgSU510";
    $consumer_key = "RXKTrdedwfCv94S70BmKg";
    $consumer_secret = "cdLoF9Vcy7WMYurMywsJVXHgEy8olhMqIUDCYms8";
    $oauth = array('screen_name' => 'neilcarpenter', 'count' => $count, 'oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
    $base_info = buildBaseString($url, 'GET', $oauth);
    $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
    $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
    $oauth['oauth_signature'] = $oauth_signature;
    // Make Requests
    $header = array(buildAuthorizationHeader($oauth), 'Expect:');
    $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=neilcarpenter&count=' . $count, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
    $feed = curl_init();
    curl_setopt_array($feed, $options);
    $json = curl_exec($feed);
    curl_close($feed);
    //$twitter_data = json_decode($json);
    return $json;
}
开发者ID:neilcarpenter,项目名称:neilcarpenter.com-V1,代码行数:22,代码来源:functions.php

示例12: index

 public function index()
 {
     $bbConfig = array();
     $bbConfig['access_token'] = $this->fetch('access_token', null, null, false, false);
     $bbConfig['access_token_secret'] = $this->fetch('access_token_secret', null, null, false, false);
     $bbConfig['consumer_key'] = $this->fetch('consumer_key', null, null, false, false);
     $bbConfig['consumer_secret'] = $this->fetch('consumer_secret', null, null, false, false);
     $count = $this->fetchParam('count', 5, 'is_numeric');
     $screen_name = $this->fetchParam('screen_name', null);
     $include_rts = $this->fetchParam('include_rts', true);
     $include_entities = $this->fetchParam('include_entities', true);
     $exclude_replies = $this->fetchParam('exclude_replies', false);
     $cache_length = $this->fetchParam('cache', 60);
     // Cache time in seconds
     // Check the cache before continuing. We don't want to hit the API on every request.
     $cached_tweets = $this->cache->getYAML($screen_name);
     if ($cached_tweets) {
         // If there's a cache and it's older than our specified time, delete it. It'll be recreated later.
         if ($this->cache->getAge($screen_name) >= $cache_length) {
             $this->cache->delete($screen_name);
         } else {
             return $cached_tweets;
         }
     }
     function buildBaseString($baseURI, $method, $params)
     {
         $r = array();
         ksort($params);
         foreach ($params as $key => $value) {
             $r[] = "{$key}=" . rawurlencode($value);
         }
         return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
         //return complete base string
     }
     function buildAuthorizationHeader($oauth)
     {
         $r = 'Authorization: OAuth ';
         $values = array();
         foreach ($oauth as $key => $value) {
             $values[] = "{$key}=\"" . rawurlencode($value) . "\"";
         }
         $r .= implode(', ', $values);
         return $r;
     }
     $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
     if ($exclude_replies == true) {
         $query = array('count' => $count, 'screen_name' => $screen_name, 'include_rts' => $include_rts, 'exclude_replies' => $exclude_replies, 'include_entities' => $include_entities);
     } else {
         $query = array('count' => $count, 'screen_name' => $screen_name, 'include_rts' => $include_rts, 'include_entities' => $include_entities);
     }
     $oauth_access_token = $bbConfig['access_token'];
     $oauth_access_token_secret = $bbConfig['access_token_secret'];
     $consumer_key = $bbConfig['consumer_key'];
     $consumer_secret = $bbConfig['consumer_secret'];
     $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
     $base_params = empty($query) ? $oauth : array_merge($query, $oauth);
     $base_info = buildBaseString($url, 'GET', $base_params);
     $url = empty($query) ? $url : $url . "?" . http_build_query($query);
     $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
     $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
     $oauth['oauth_signature'] = $oauth_signature;
     $header = array(buildAuthorizationHeader($oauth), 'Expect:');
     $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
     $feed = curl_init();
     curl_setopt_array($feed, $options);
     $json = curl_exec($feed);
     curl_close($feed);
     $twitter_data = json_decode($json);
     if (isset($twitter_data)) {
         $tweets = theNest($twitter_data);
         $output = array("tweets" => array(), "user" => array());
         foreach ($tweets as $tweet) {
             $tweetText = $tweet['text'];
             if (isset($tweet['entities'])) {
                 if (is_array($tweet['entities']['urls'])) {
                     $entityUrl = $tweet['entities']['urls'];
                 }
                 if (is_array($tweet['entities']['hashtags'])) {
                     $entityHash = $tweet['entities']['hashtags'];
                 }
                 if (is_array($tweet['entities']['user_mentions'])) {
                     $entityUser = $tweet['entities']['user_mentions'];
                 }
             }
             if (!empty($entityUrl) || !empty($entityHash) || !empty($entityUser)) {
                 foreach ($entityUrl as $url) {
                     $find = $url['url'];
                     $replace = '<a href="' . $find . '">' . $url['display_url'] . '</a>';
                     $tweetText = str_replace($find, $replace, $tweetText);
                 }
                 foreach ($entityHash as $hashtag) {
                     $find = '#' . $hashtag['text'];
                     $replace = '<a href="https://twitter.com/#!/search/%23' . $hashtag['text'] . '">' . $find . '</a>';
                     $tweetText = str_replace($find, $replace, $tweetText);
                 }
                 foreach ($entityUser as $user_mention) {
                     $find = "@" . $user_mention['screen_name'];
                     $replace = '<a href="https://twitter.com/' . $user_mention['screen_name'] . '">' . $find . '</a>';
                     $tweetText = str_replace($find, $replace, $tweetText);
                 }
//.........这里部分代码省略.........
开发者ID:roobottom,项目名称:roobottom-statamic,代码行数:101,代码来源:pi.bluebird.php

示例13: implode

    }
    $r .= implode(', ', $values);
    return $r;
}
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$oauth_access_token = "UPDATE ME";
$oauth_access_token_secret = "UPDATE ME";
$consumer_key = "UPDATE ME";
$consumer_secret = "UPDATE ME";
$oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'screen_name' => $twitter_handle);
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), 'Content-Type: application/json', 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=' . $twitter_handle, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
?>

<!DOCTYPE html>
<html>
<head>
<title>Twitter Live PHP Testing</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/zkniebel/jquery-twitter-feed/master/jquery-twitter-feed.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
开发者ID:rishabhthakur,项目名称:jquery-twitter-feed,代码行数:31,代码来源:Ready_PHP.php

示例14: getTwitterFeed

function getTwitterFeed()
{
    /*
     * Build and sort the URL variables for Twitter Oauth Request
     * 
     * @param string $baseURI - URI for Twitter
     * @param string $method  - Method (GET or POST) to use when transmitting
     * @param array $params   - Required Oauth parameters sent to Twitter
     * @return string
     */
    function buildBaseString($baseURI, $method, $params)
    {
        $r = array();
        ksort($params);
        foreach ($params as $key => $value) {
            $r[] = "{$key}=" . rawurlencode($value);
        }
        return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
    }
    /*
     * Build the Oauth Header for Twitter
     * 
     * @param array $oauth - options for header elements
     * @return string
     */
    function buildAuthorizationHeader($oauth)
    {
        $r = 'Authorization: OAuth ';
        $values = array();
        foreach ($oauth as $key => $value) {
            $values[] = "{$key}=\"" . rawurlencode($value) . "\"";
        }
        $r .= implode(', ', $values);
        return $r;
    }
    /**
     * Make any URLs in Twitter posts clickable links
     * 
     * @param string $string - A string that might contain a URL
     * @return string
     */
    function makeLink($string)
    {
        /*** make sure there is an http:// on all URLs ***/
        /*$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);*/
        $string = preg_replace("#(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $string);
        $string = preg_replace("#(^|[\n ])((www)\\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $string);
        /*** Turn Any @ symbol into a link ***/
        $string = preg_replace("/@(\\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $string);
        /*** Turn any # symbol into a link ***/
        $string = preg_replace("/#(\\w+)/", "<a href=\"http://twitter.com/search?q=%23\\1\" target=\"_blank\">#\\1</a>", $string);
        return $string;
    }
    /*
     * Check for Cached Version of Feed
     * if not cached, create cache version
     */
    $isScode = $sCode;
    $sstf_transient = get_transient('sstf_cached');
    if (!$sstf_transient || trim(esc_attr(get_option('sstf_consumer_twitter_cache_time'))) == '0') {
        //Remove any Transient Value
        delete_transient('sstf_cached');
        delete_transient('sstf_sCode');
        //Oauth settings
        $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
        $consumer = trim(esc_attr(get_option('sstf_consumer_screen_name')));
        $consumer_num = trim(esc_attr(get_option('sstf_consumer_num')));
        $consumer_links = trim(esc_attr(get_option('sstf_consumer_make_links')));
        $consumer_key = trim(esc_attr(get_option('sstf_consumer_key')));
        $consumer_secret = trim(esc_attr(get_option('sstf_consumer_secret')));
        $oauth_access_token = trim(esc_attr(get_option('sstf_consumer_token')));
        $oauth_access_token_secret = trim(esc_attr(get_option('sstf_consumer_token_secret')));
        $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'count' => $consumer_num, 'screen_name' => $consumer);
        $base_info = buildBaseString($url, 'GET', $oauth);
        $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
        $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
        $oauth['oauth_signature'] = $oauth_signature;
        // Make cURL Request to Twitter
        $header = array(buildAuthorizationHeader($oauth), 'Expect:');
        $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=' . $consumer . '&count=' . $consumer_num, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
        $feed = curl_init();
        curl_setopt_array($feed, $options);
        $json = curl_exec($feed);
        curl_close($feed);
        $twitter_data = json_decode($json, true);
        /*
         * format the feed
         */
        $t = 0;
        $sstfTweet = '';
        $sstfTweetLinks = '';
        $wrapTweet = false;
        $closeUl = '';
        $sstfElement = trim(esc_attr(get_option('sstf_consumer_element')));
        if ($sstfElement) {
            if ($sstfElement == "li") {
                $sstfTweetLinks = '<ul class="sstfeedwrap">';
                $closeUl = "</ul>";
            }
            $wrapTweet = true;
//.........这里部分代码省略.........
开发者ID:rodsilver83,项目名称:victoria,代码行数:101,代码来源:supersimpletwitterfeed.php

示例15: display_latest_tweets

function display_latest_tweets($twitter_user_id, $cache_file = './twitter.txt', $tweets_to_display = 3, $ignore_replies = false, $twitter_wrap_open = '<ul id="twitter">', $twitter_wrap_close = '</ul>', $tweet_wrap_open = '<li class="clearfix tweet">', $meta_wrap_open = '', $meta_wrap_close = '', $tweet_wrap_close = '</li>', $date_format = 'd-m-Y H:i', $twitter_style_dates = false)
{
    // Seconds to cache feed (1 hour).
    $cachetime = 60 * 60;
    // Time that the cache was last filled.
    $cache_file_created = file_exists($cache_file) ? filemtime($cache_file) : 0;
    // A flag so we know if the feed was successfully parsed.
    $tweet_found = false;
    // Show file from cache if still valid.
    if (time() - $cachetime < $cache_file_created && 1 == 2) {
        $tweet_found = true;
        // Display tweets from the cache.
        readfile($cache_file);
    } else {
        // Cache file not found, or old. Fetch the RSS feed from Twitter.
        $oauth_access_token = "105725270-kGXv4JQ40XDlx6Qaw2ET27T3BeQISIsJMewtjaMN";
        $oauth_access_token_secret = "QFG28u5p8I1IJZNWbKySTPbCntWXnSM6sTsFTz9AZQ";
        $consumer_key = "NdzOu5NyfyT8962hkmbyog";
        $consumer_secret = "BU2I2ABWue5npS2GsG3f7M6YrGDJkRLn2qchXvN44";
        $twitter_timeline = "user_timeline";
        //  mentions_timeline / user_timeline / home_timeline / retweets_of_me
        //  create request
        $request = array('screen_name' => $twitter_user_id, 'count' => $tweets_to_display);
        $oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
        $oauth = array_merge($oauth, $request);
        //  do some magic
        $base_info = buildBaseString("https://api.twitter.com/1.1/statuses/{$twitter_timeline}.json", 'GET', $oauth);
        $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
        $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
        $oauth['oauth_signature'] = $oauth_signature;
        //  make request
        $header = array(buildAuthorizationHeader($oauth), 'Expect:');
        $options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => "https://api.twitter.com/1.1/statuses/{$twitter_timeline}.json?" . http_build_query($request), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
        $feed = curl_init();
        curl_setopt_array($feed, $options);
        $json = curl_exec($feed);
        curl_close($feed);
        $rss = json_decode($json, true);
        //$rss = file_get_contents('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$twitter_user_id);
        if ($rss) {
            // Parse the RSS feed to an XML object.
            //$xml = simplexml_load_string($rss);
            $xml = $rss;
            if ($xml !== false) {
                // Error check: Make sure there is at least one item.
                if (sizeof($xml) > 0) {
                    $tweet_count = 0;
                    // Start output buffering.
                    ob_start();
                    // Open the twitter wrapping element.
                    $twitter_html = $twitter_wrap_open;
                    //echo "<pre>".print_r($rss,true)."</pre>";
                    // Iterate over tweets.
                    foreach ($rss as $tweet) {
                        // Twitter feeds begin with the username, "e.g. User name: Blah"
                        // so we need to strip that from the front of our tweet.
                        //$tweet_desc = substr($tweet["text"],strpos($tweet["text"],":")+2);
                        $tweet_desc = $tweet["text"];
                        $tweet_desc = htmlspecialchars($tweet_desc);
                        $tweet_first_char = substr($tweet_desc, 0, 1);
                        // If we are not ignoring replies, or tweet is not a reply, process it.
                        if ($tweet_first_char != '@' || $ignore_replies == false) {
                            $tweet_found = true;
                            $tweet_count++;
                            // Add hyperlink html tags to any urls, twitter ids or hashtags in the tweet.
                            $tweet_desc = preg_replace('/(https?:\\/\\/[^\\s"<>]+)/', '<a href="$1">$1</a>', $tweet_desc);
                            $tweet_desc = preg_replace('/(^|[\\n\\s])@([^\\s"\\t\\n\\r<:]*)/is', '$1<a href="http://twitter.com/$2">@$2</a>', $tweet_desc);
                            $tweet_desc = preg_replace('/(^|[\\n\\s])#([^\\s"\\t\\n\\r<:]*)/is', '$1<a href="http://twitter.com/search?q=%23$2">#$2</a>', $tweet_desc);
                            // Convert Tweet display time to a UNIX timestamp. Twitter timestamps are in UTC/GMT time.
                            $tweet_time = strtotime($tweet["created_at"]);
                            if ($twitter_style_dates) {
                                // Current UNIX timestamp.
                                $current_time = time();
                                $time_diff = abs($current_time - $tweet_time);
                                switch ($time_diff) {
                                    case $time_diff < 60:
                                        $display_time = $time_diff . ' seconds ago';
                                        break;
                                    case $time_diff >= 60 && $time_diff < 3600:
                                        $min = floor($time_diff / 60);
                                        $display_time = $min . ' minutes ago';
                                        break;
                                    case $time_diff >= 3600 && $time_diff < 86400:
                                        $hour = floor($time_diff / 3600);
                                        $display_time = 'about ' . $hour . ' hour';
                                        if ($hour > 1) {
                                            $display_time .= 's';
                                        }
                                        $display_time .= ' ago';
                                        break;
                                    default:
                                        $display_time = date($date_format, $tweet_time);
                                        break;
                                }
                            } else {
                                $display_time = date($date_format, $tweet_time);
                            }
                            $display_time = strtoupper($display_time);
                            // Render the tweet.
                            $twitter_html .= '<p class="time">' . $display_time . '</p>' . $tweet_wrap_open . html_entity_decode($tweet_desc) . $tweet_wrap_close;
//.........这里部分代码省略.........
开发者ID:estrategasdigitales,项目名称:glummer,代码行数:101,代码来源:functions-televisa.php


注:本文中的buildAuthorizationHeader函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。