示例#1
0
<?php

require '../common/globals.php';
require '../common/twitter-php-3.2/src/twitter.class.php';
// Fill in the next 2 variables.
$access_token = '15201275-loypZtq58TRB1qoIIu6fTw6TSEqluGZ1aMKgVJjJe';
$access_token_secret = 'haKjTuzH9N6UPhOBZDKSsu6FAZzIvLNbwGhi5wfy00Y';
$twitter = new Twitter(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $access_token, $access_token_secret);
try {
    $results = $twitter->search('#ibm');
    foreach ($results as $result) {
        echo "message: ", $result->text;
        echo "posted at ", $result->created_at;
        echo "posted by ", $result->form_user;
    }
    echo "\n\n\n\n";
} catch (TwitterException $e) {
    echo "Error searching Twitter: ", $e->getMessage();
}
try {
    $statuses = $twitter->request('statuses/retweets_of_me', 'GET', array('count' => 20));
    foreach ($statuses as $status) {
        echo "message: ", $status->text;
        echo "posted at ", $status->created_at;
        echo "posted by ", $status->form_user;
    }
    echo "\n\n\n\n";
} catch (TwitterException $e) {
    echo "Error getting statuses from Twitter: ", $e->getMessage();
}
try {
示例#2
0
-------------------------------------------------------------------------------------------------*/
echo "<h2>Trends</h2>";
$trendsDaily = $twitter->trends();
# Loop through the results
foreach ($trendsDaily['trends'] as $thisTrend) {
    # Echo out each tweet
    echo $thisTrend['name'] . "<br/>";
}
echo "<br/><br/>";
# For debugging purposes we can echo out the full array of the results
//print_r($trendsDaily['trends']);
/*-------------------------------------------------------------------------------------------------
SEARCH
-------------------------------------------------------------------------------------------------*/
$keyword = "apples";
echo "<h2>Search for '" . $keyword . "'</h2>";
$searchResults = $twitter->search($keyword);
# Loop through the results
foreach ($searchResults['results'] as $thisResult) {
    $tweet = $thisResult['text'];
    $tweet = str_ireplace($keyword, "<span style='background-color:yellow'>" . $keyword . "</span>", $tweet);
    echo $tweet . "<br/><br/>";
}
echo "<br/><br/>";
# For debugging purposes we can echo out the full array of the results
//print_r($searchResults);
?>
 


示例#3
0
文件: search.php 项目: iplayfast/sc
<?php

require_once '../twitter.class.php';
$twitter = new Twitter();
$results = $twitter->search('#nette');
// or use hashmap: $results = $twitter->search(array('q' => '#nette', 'geocode' => '50.088224,15.975611,20km'));
?>
<!doctype html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Twitter search demo</title>

<ul>
<?php 
foreach ($results as $result) {
    ?>
	<li><a href="http://twitter.com/<?php 
    echo $result->from_user;
    ?>
"><img src="<?php 
    echo htmlspecialchars($result->profile_image_url);
    ?>
" width="48">
		<?php 
    echo htmlspecialchars($result->from_user);
    ?>
</a>:
		<?php 
    echo Twitter::clickable($result->text);
    ?>
		<small>at <?php 
    echo date("j.n.Y H:i", strtotime($result->created_at));
示例#4
0
* @copyright  Copyright (C) 2016 Isi Roca
* @link       http://isiroca.com
* @since      File available since Release 1.0.0
* @license    https://opensource.org/licenses/MIT  The MIT License (MIT)
* @see        https://github.com/IsiRoca/Twitter-Search/issues
*
*/
// Require autoload file
require_once dirname(__FILE__) . '/src/autoload.php';
// Get Twitter connection
$twitter = new Twitter($consumerKey, $consumerSecret, $oauthAccessToken, $oauthAccessTokenSecret);
// Get query from form
if (isset($_GET['q'])) {
    $query = $_GET['q'];
    if (!empty($query)) {
        $q = $twitter->search($query);
        $results = array_slice($q, 0, $maxResponse);
    }
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">
示例#5
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('search/{keyword}', function ($keyword) {
    $result = Twitter::search($keyword);
    return view('search')->with('result', array_fetch($result['statuses'], 'text'));
});
示例#6
0
 /**
  * Searches for multiple keywords
  * @param array keywords The keywords to search for
  * @param string since_id Limit results to entries starting after since_id 
  * @param boolean search_or search using OR or AND
  */
 static function search_multiple($keyword, $since_id = null, $search_or = true)
 {
     $entries = array();
     // Filter: tweeds containing links only.
     // This Filter doesn't work at the moment, will produce an empty result!
     // It is not neccessary for us, only a hint for twitter.
     // rpp: results per page
     $filter = '';
     // +filter:links
     if (!empty($since_id)) {
         $filter .= "&since_id={$since_id}";
     }
     $query = $keyword;
     //urlencode($keyword);
     // Filter will be added to the query, so substract it.
     $max_query_len = 139 - strlen($filter);
     // Now execute the queries
     $api = new Twitter();
     $newentries = $api->search($query . $filter, $entries);
     if ($newentries === false) {
         // Error occured, mostly resultet in an twitter overload!
         echo "<b>Search qry</b>: " . $api->get_search_url() . ".json?q={$query}{$filter}<br/>";
         echo "<b>Error code</b>: " . $api->twitter_errors[$api->last_error] . " ({$api->last_error})<br/>";
         if (!empty($api->error_response)) {
             $response = json_decode($api->error_response);
             if (!empty($response->error)) {
                 $errormsg = $response->error;
             } else {
                 $errormsg = $api->error_response;
             }
             echo "<b>Error Resp</b>: {$errormsg}<br/>";
         }
         $newentries = array();
     }
     $entries = $newentries;
     return $entries;
 }