Buongiorno a tutti,
è la prima volta che scrivo in questo forum. Pensavo di farcela da solo, pensavo di trovare una soluzione e invece sono qui a scriverVi, e siete la mia ultima chance per la mia ricerca.
Per mia sfortuna conosco poco di Php e purtroppo ho dovuto cercare in rete un Script PHP che mi consentisse di estrapolare i Tweets con un determinato hashtag, per poi farlo girare con easyPHP o XamPP.
Ne ho trovati due:
il primo (SCIPT A), estrapola solo gli ultimi 15 tweets e a me servirebbero molti di più, ma non riesco a modificare lo script affinché butti giù il maggior numero di tweets possibili(ho trovato online solo alcune app FREE che scaricano al massimo 3200 tweets, però lo fanno solo per username NON per HASHTAGS);
il secondo (SCRIPT B), estrapola 10 tweets(posso modificare la terza riga e arrivare al massimo a 100, ma sono comunque pochi...) ma NON stampa la funzione data/ora di QUANDO E' STATO SCRITTO IL MESSAGGIO, fondamentale per la mia ricerca.
Di seguito gli script:
SCRIPT A:
<?php
$pagetitle = "Pull Twitter Hashtags";
function getTweets($hash_tag)
{
$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag).'&result_type =recent' ;
echo "
Connecting to $url ...</p>";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
//If you want to see the response from Twitter, uncomment this next part out:
//echo "
Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";
$affected = 0;
$twelement = new SimpleXMLElement($xml);
foreach ($twelement->entry as $entry) {
$text = trim($entry->title);
$author = trim($entry->author->name);
$time = strtotime($entry->published);
$id = $entry->id;
//echo count($entry->text);
echo "
Tweet from ".$author.": ".$text." Posted ".date('n/j/y g:i a',$time)."</p>";
}
return true ;
}
getTweets('#converse');
?>
SCRIPT B
<?php
$hashtag = 'php'; // We search Twitter for the hashtag #php
$show = 10; // And we want to get 10 tweets
$cacheFile = 'cache/' . $hashtag .'.json.cache'; // A cachefile will be placed in cache/
$cacheTime = 1 * 60; // 1 minute cache time
// If the cache file is newer than our cache time, get the content of it
if (file_exists($cacheFile) && (time() - $cacheTime < filemtime($cacheFile))) {
$json = file_get_contents($cacheFile);
}
// If it's older, place a new cache file into our cache folder with the JSON result of the twitter search
else {
$json = file_get_contents("http://search.twitter.com/search.json?result_type=recent&rpp=$show&q=%23" . $hashtag);
$fp = fopen($cacheFile, 'w');
fwrite($fp, $json);
fclose($fp);
}
// Get the results
$results = json_decode($json)->results;
// Format the Tweet
function displayTweet($text) {
// Links
$text = preg_replace('@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@', '$1',$text);
// Users
$text = preg_replace('/@(\w+)/','@$1',$text);
return $text;
// Hashtags
$text = preg_replace('/#(\w+)/','#$1',$text);
}
?>
<?php foreach($results as $result) { ?>
<div class="tweetByTag">
<div class="tweet">
<?php echo displayTweet($result->text),"\r\n"; ?>
<?php echo "
Tweet from ".$author.": ".$text." [i]Posted ".date('n/j/y g:i a',$time)." ?>
</div>
<div class="by"><?php echo $result->from_user ?></div>
</div>
<? } ?>
Ho cercato in tutti i modi di risolvere la soluzione ma niente da fare;
Spero molto possiate essermi d'aiuto.
Vi ringrazio tutti comunque, per mettere a disposizione di tutti la vostra competenza, frutto di anni di intenso studio e passione;
Saluti a tutti,
bischio