0

Retrieving Tweets

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 StumbleUpon Eli Pets

chin yee

Leave a Reply

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

Current day month ye@r *

What is 11 + 12 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)