2010-01-12 112 views
2

我有一个网站与用户的数据库,我想让他们能够显示他们的个人资料页面上他们当前的鸣叫消息(如果他们有一个Twitter帐户)。分享上一个网页的最后一个鸣叫

搜索后,我看到了这个工具:http://juitter.com 这似乎是只是我需要有点复杂。

我正在使用Rails。你知道一个尽可能简单的工具可以做到吗?

谢谢 d

回答

4

你可以看看Twitter的API:users/show

例子:

$ 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, 
... 
} 

你可以得到最后的鸣叫用简单的jQuery电话:

<!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> 
+0

非常感谢!只是最后一个问题:我怎样才能得到配置文件的id号? (例如来自http://twitter.com/yukihiro_matz) – Denis 2010-01-12 11:24:47

+2

看看页面的html源代码。有几个对用户标识的引用,例如'http://twitter.com/statuses/user_timeline/20104013.rss'。我没有深入研究这个问题,但我会建议你的用户直接提供他们的推特ID,或者你一次抓取页面以获取用户ID并将其存储在本地服务器上。这只是一个快速回复..你可能会找到更好的方法来实现这个.. – miku 2010-01-12 11:33:42

0

看看在twitter宝石。它使用起来非常简单。

+0

谢谢约翰为这个宝石,我会看到它:) – Denis 2010-01-12 11:25:50

0

mikus答案没为我工作,我得到了

XMLHttpR equest无法加载http://twitter.com/users/show/ditact.json。 Access-Control-Allow-Origin不允许原产地http://mydomain.com

我发现Accessing JSON service from localhost or file://

的一种方式回答,以绕过同源策略是加载JSONP而不是JSON。 你可以使用twitter API和jQuery来做到这一点,你只需要添加“callback =?”网址。

<!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> 
相关问题