Beispiel #1
0
    <style type="text/css" media="print"> 
		@import url("print.css");
	</style> 
</head>
<body>
<form action="index.php" method="submit">
<input name="twitterq" type="text" id="twitterq" />
<input name="Search" type="submit" value="Search" />
</form>
<?php 
include 'TwitterSearch.phps';
if ($_GET['twitterq']) {
    $twitter_query = $_GET['twitterq'];
    echo '<div><p>Query is: ' . $twitter_query . '</p></div>';
    $search = new TwitterSearch($twitter_query);
    $search->rpp(100);
    $results = $search->results();
    if (count($results) < 1) {
        echo '<div><p>No results found</p></div>';
    }
    $odd = true;
    echo '<table class="master"><tr><td class="left">';
    foreach ($results as $result) {
        $odd = !$odd;
        $oddEven = $odd ? "odd" : "even";
        echo '<div class="twitter_status ' . $oddEven . '">';
        echo '<img src="' . $result->profile_image_url . '" class="twitter_image">';
        // replace embedded URLs
        $text_n = preg_replace('/https?:\\/\\/[^\\s]+/i', '<a href="$0" target="output">$0</a>', $result->text);
        // toLink($result->text);
        echo $text_n;
<?php

include "TwitterSearch.phps";
$term = $_GET['term'];
$what = $_GET['what'];
$search = new TwitterSearch($term);
$search->user_agent = 'phptwittersearch:rajarshi.guha@gmail.com';
$results = $search->rpp(50000)->results();
#print_r($results[0]);
if ($what == "text") {
    $ret = "";
    foreach ($results as $result) {
        $ret = $ret . " " . $result->{'text'};
    }
    # remove some common words - we do this here
    # as I can't see how to make the jQuery plugin
    # to this
    $needles = array(" RT ", " #ACS_Boston ", " Meeting ", "ACSNatlMtg", "OK", "ACS", "Boston", "Visit", "Meeting", "Still", "Just", "Need", "Want", "Attending", "Getting", "SADI", "Join", "Currently", "Meet", "Everyone", "Hotel", "Seaport", "Ballroom", "June", "Guess", "Session", "Follow", "First", "LeighJKBoerner", "Booth", "PM", "PSI", "Monday", "Will", "Somewhere");
    foreach ($needles as $needle) {
        $ret = str_replace($needle, "", $ret);
    }
    echo $ret;
} else {
    if ($what == "author") {
        $ret = array();
        foreach ($results as $result) {
            $author = $result->{'from_user'};
            if ($ret[$author] == NULL) {
                $ret[$author] = 1;
            } else {
                $ret[$author] = $ret[$author] + 1;
Beispiel #3
0
require "./lib/TwitterSearch.php";
$id = "";
// Id of the last recived tweet
$file = fopen("id.txt", "r+");
// The last rquests tweet id is stored in id.txt
$id = $id . fgets($file);
// Read the last tweet id to $id
$search = new TwitterSearch('"i love you"');
// Initialize search class with query "i love you"
$search->user_agent = 'phptwittersearch:emotion@gmail.com';
// Set the user agent, something twitter API would like us to set!
if ($id != 0) {
    // well if id!=0, that is the initial case or first run get just two tweets to start the timeline
    $results = $search->since($id)->rpp(100)->results();
} else {
    $results = $search->rpp(2)->results();
}
// Just get 2 tweets just to get the id of the tweet which ca be used in futeure request
$id = $results[0]->id_str;
// get the id of the first tweet ie., latest tweet
$file = fopen("id.txt", "w+");
fwrite($file, $id);
//write the id to file id.txt, so we can retieve the id in next request
fclose($file);
// Set the JSON header
header("Content-type: text/json");
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;
// values for x-axis of the graph
$y = sizeof($results);
// sizeof($results) gives us the number of tweet results returned or the number tweets with "i love you"