2

I have a website with a database of users and I would like to allow them to display on their profile page their current tweet message (if they have a Twitter account).

After searching, I had seen this tool: http://juitter.com It seems to be a little bit complex for just my needs.

I am working with Rails. Do you know a tool as simple as possible which can do that?

Thank you D

John Topley
  • 113,588
  • 46
  • 195
  • 237
Denis
  • 223
  • 1
  • 7
  • 13

3 Answers3

4

You may look at the twitter api: users/show

Example:

$ curl http://twitter.com/users/show/20536157.json
{"notifications":false,"time_zone":"Pacific Time (US &
Canada)","friends_count":214,
"profile_sidebar_border_color":"bbccff","url":"http://www.google.com/support/",
"description":"News and updates from Google","status":{"created_at":"Mon Jan
11 19:38:40 +0000
2010","source":"web","truncated":false,"favorited":false,
"in_reply_to_user_id":null,
"in_reply_to_status_id":null,"in_reply_to_screen_name":null,"id":7640306427,

"text":"If
you're interested in what's happening with @google in Sub-Saharan Africa,
check out the new @googleafrica for news &
info."},

"geo_enabled":false,"favourites_count":73, "created_at":"Tue Feb 10
19:14:39 +0000 2009","profile_text_color":"000000","verified":false,
...
}

You can get the last tweet with a simple jquery call:

<!DOCTYPE html>
<html>
<head>
    <script src="http://www.google.com/jsapi"></script>
    <script>google.load("jquery", "1");</script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
            $.getJSON("http://twitter.com/users/show/20536157.json",
                function(data){ $("#tweet").text(data.status.text); });
        });
    </script>
</head>
<body>
    <div id="tweet"><!-- last status will show up here --></div>
</body>
</html>
miku
  • 181,842
  • 47
  • 306
  • 310
  • Many thanks! Just a last question: how can I get the id number of a profile? (for instance from: http://twitter.com/yukihiro_matz) – Denis Jan 12 '10 at 11:24
  • 2
    Look at the page html source. There are a couple of references to the user id, e.g. 'http://twitter.com/statuses/user_timeline/20104013.rss'. I haven't look into this issue in-depth, but i would suggest, that your users either provide their twitter id directly or you scrape the page one time to get the user id and store it locally on your server. That's just a quick reply .. you may find a better way to implement this .. – miku Jan 12 '10 at 11:33
0

Take a look at the twitter gem. It's super simple to use.

John Topley
  • 113,588
  • 46
  • 195
  • 237
0

mikus answer didn't work for me, I got

XMLHttpRequest cannot load http://twitter.com/users/show/ditact.json. Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin.

I found the answer in Accessing JSON service from localhost or file://

One way to get around the same origin policy is to load JSONP instead of JSON. You can do this with the twitter API and jQuery, you just have to add "callback=?" the URL.

<!DOCTYPE html>
<html>
<head>
    <script src="http://www.google.com/jsapi"></script>
    <script>google.load("jquery", "1");</script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
                                                               // vvvvvvvvvvv
            $.getJSON("http://twitter.com/users/show/20536157.json?callback=?", 
                                                               // ^^^^^^^^^^^
                function(data){ $("#tweet").text(data.status.text); });
        });
    </script>
</head>
<body>
    <div id="tweet"><!-- last status will show up here --></div>
</body>
</html>
Community
  • 1
  • 1
bjelli
  • 9,752
  • 4
  • 35
  • 50