Retrieving Tweets

Tags: ,

Add the following to the index.html (Replace “chyneyee” with your Twitter username):


<script src="https://api.twitter.com/1/statuses/user_timeline/chyneyee.json?callback=updateTweets"></script>

Add the following code to the js file:


// tweets passed a response containing the tweets from the user timeline as an array of tweets.
function updateTweets(tweets) {
 var tweetsSelection=document.getElementById("tweets"); // grab a reference to the tweets selection from the form.
 for (var i=0;i<tweets.length;i++) {
 tweet = tweets[i]; // get a tweet from the array
 var option=document.createElement("option"); // Create a new option element
 option.text=tweet.text; // Set its text to the tweet
 option.value=tweet.text.replace("\"","'"); // replace double quotes with single quotes
 tweetsSelection.options.add(option);
 }
 tweetsSelection.selectedIndex=0;
}

Output:

Twitter Output

Article Global Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google Yahoo Buzz StumbleUpon Eli Pets


Rate This Post

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>