Get a tweet from user timeline using JSON and jQuery


/ Published in: jQuery
Save to your folder(s)

Updated code (December, 2012) to get a tweet from a user's twitter timeline using JSON and jQuery


Copy this code and paste it in your HTML
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>JSON Example</title>
  5. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
  6. <script type="text/javascript">
  7. function getTweet(){
  8. $.getJSON("https://api.twitter.com/1/statuses/user_timeline/uniofgreenwich.json?count=1&callback=?",
  9. function(data){
  10. $("#twitter").html("<a href='http://twitter.com/#!/uniofgreenwich/status/"+data[0].id_str+"'>" + data[0].text + "</a>");
  11. });
  12. }
  13.  
  14. $(document).ready(function(){
  15. getTweet();
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <p id="twitter"></p>
  21. </body>
  22. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.