2012-02-28 2 views
7

He estado leyendo el sitio de desarrolladores de Twitter, pero no hay un método en la RESP API para hacer eso, creo que es con Streaming Api, ¿alguien me puede guiar para hacer esto ?, quiero algo similar a tweetstats, solo enséñame las palabras más tuiteadas.¿cómo recupero las palabras que escribí en Twitter más?

gracias por responder

+0

ayuda por favor, por favor !! una pista, un consejo, lo que sea – bentham

+0

Según las respuestas a esta pregunta, no parece que el twitter tenga un historial http://stackoverflow.com/questions/1662151/getting-historical-data-from-twitter –

+0

Sé que así que quiero saber por una semana – bentham

Respuesta

10

Esto utiliza la API REST, no el API de Streaming, pero creo que va a hacer lo que busca. La única limitación es que está limitada por la API REST a los últimos 200 tweets, por lo que si tienes más de 200 tweets en la última semana, solo hará un seguimiento de las palabras de tus 200 tweets más recientes.

Asegúrese de reemplazar el nombre de usuario en la llamada API con su nombre de usuario deseado.

<?php 

//Get latest tweets from twitter in XML format. 200 is the maximum amount of tweets allowed by this function. 
$tweets = simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=kimkardashian&count=2'); 

//Initiate our $words array 
$words = array(); 

//For each tweet, check if it was created within the last week, if so separate the text into an array of words and merge that array with the $words array 
foreach ($tweets as $tweet) { 
    if(strtotime($tweet->created_at) > strtotime('-1 week')) { 
     $words = array_merge($words, explode(' ', $tweet->text)); 
    } 
} 

//Count values for each word 
$word_counts = array_count_values($words); 

//Sort array by values descending 
arsort($word_counts); 

foreach ($word_counts as $word => $count) { 
    //Do whatever you'd like with the words and counts here 
} 

?> 
+0

gracias por responder solo esperando Si alguien sabe de una mejor manera – bentham

+2

Si buscas algo mejor, en mi humilde opinión necesitas definir "mejor" –

Cuestiones relacionadas