本文整理汇总了PHP中buildBaseString函数的典型用法代码示例。如果您正苦于以下问题:PHP buildBaseString函数的具体用法?PHP buildBaseString怎么用?PHP buildBaseString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buildBaseString函数的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);
}
示例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));
}
示例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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: explode
break;
case '1':
$dividir = explode('/?', $url);
$dividir = is_array($dividir) ? $dividir : explode('?', $url);
$urls = is_array($dividir) ? $dividir[0] : $dividir;
$dividir = is_array($dividir) ? explode('twitter.com/', $dividir[0]) : explode('twitter.com/', $dividir);
$terminoBuscar = $dividir['1'];
$url = "https://api.twitter.com/1.1/users/search.json";
$query = array('count' => 6, 'q' => urlencode($terminoBuscar), "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);
$resultTwitter = json_decode($json);
for ($i = 0; $i < count($resultTwitter); $i++) {
if ($resultTwitter[$i]->screen_name == $terminoBuscar) {
$resultTwitter = $resultTwitter[$i];
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/publication/search/results/resultTwitter.json', 'w');
示例9: file
$camps = file('data-camps.txt', FILE_IGNORE_NEW_LINES);
$TWITTER_CHARACTER_LIMIT = 140;
$markov = new Markov();
$markov->init($titles);
$title = $markov->generate(4);
$markov = new Markov();
$markov->init($camps);
$camp = $markov->generate(4);
$chain = "{$title} @ {$camp} (" . address() . ") #burningman #bot";
if (strlen($chain) >= $TWITTER_CHARACTER_LIMIT) {
// try again
composeTweet();
} else {
return $chain;
}
}
// echo composeTweet();
$url = "https://api.twitter.com/1.1/statuses/update.json";
$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, 'POST', $oauth);
// echo $base_info;
$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_POSTFIELDS => array('status' => composeTweet()), 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);
示例10: 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);
}
//.........这里部分代码省略.........
示例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;
}
示例12: indonez_get_twitter_timeline
function indonez_get_twitter_timeline($twitter_id, $max_tweets, $consumer_key, $consumer_secret, $user_token, $user_secret)
{
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$oauth_access_token = $user_token;
$oauth_access_token_secret = $user_secret;
$consumer_key = $consumer_key;
$consumer_secret = $consumer_secret;
$oauth = array('screen_name' => $twitter_id, 'count' => $max_tweets, '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=' . $twitter_id . '&count=' . $max_tweets, 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);
$out = '';
foreach ($twitter_data as $key => $value) {
$regex = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.\\,]*(\\?\\S+)?)?)*)@';
$text = $value->text;
$text = preg_replace('@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\./-]*(\\?\\S+)?)?)?)@', '<a target="blank" title="$1" href="$1">$1</a>', $text);
$text = preg_replace('/#([0-9a-zA-Z_-]+)/', "<a target='blank' title='\$1' href=\"http://twitter.com/search?q=\$1\">#\$1</a>", $text);
$text = preg_replace("/@([0-9a-zA-Z_-]+)/", "<a target='blank' title='\$1' href=\"http://twitter.com/\$1\">@\$1</a>", $text);
$out .= '<li>' . $text . '</li>';
}
return $out;
}
示例13: 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;
//.........这里部分代码省略.........
示例14: 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;
//.........这里部分代码省略.........
示例15: generate_twitter_oauth_token
public function generate_twitter_oauth_token()
{
function buildBaseString($baseURI, $params)
{
$r = array();
ksort($params);
foreach ($params as $key => $value) {
$r[] = "{$key}=" . rawurlencode($value);
}
return "POST&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function getCompositeKey($consumerSecret, $requestToken)
{
return rawurlencode($consumerSecret) . '&' . rawurlencode($requestToken);
}
function buildAuthorizationHeader($oauth)
{
$r = 'Authorization: OAuth ';
$values = array();
foreach ($oauth as $key => $value) {
$values[] = "{$key}=\"" . rawurlencode($value) . "\"";
}
//encode key=value string
$r .= implode(', ', $values);
return $r;
}
function sendRequest($oauth, $baseURI)
{
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $baseURI, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
exit;
return $response;
}
$baseURI = 'https://api.twitter.com/oauth/request_token';
$nonce = time();
$timestamp = time();
// $oauth_callback = "http://merlinleads.net/demo/twitter/callback";
$oauth_callback = "http://127.0.0.1/merlinleads/twitter/callback";
$oauth = array('oauth_callback' => $oauth_callback, 'oauth_consumer_key' => TWITTER_KEY, 'oauth_nonce' => $nonce, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => $timestamp, 'oauth_version' => '1.0');
$consumerSecret = TWITTER_SECRET_KEY;
$baseString = buildBaseString($baseURI, $oauth);
$compositeKey = getCompositeKey($consumerSecret, null);
$oauth_signature = base64_encode(hash_hmac('sha1', $baseString, $compositeKey, true));
$oauth['oauth_signature'] = $oauth_signature;
$response = sendRequest($oauth, $baseURI);
if (!$response) {
return null;
}
$responseArray = array();
$parts = explode('&', $response);
foreach ($parts as $p) {
$p = explode('=', $p);
$responseArray[$p[0]] = $p[1];
}
$oauth_token = $responseArray['oauth_token'];
$this->session->set_userdata('twitter_oauth_token', $oauth_token);
return $oauth_token;
}