我有一个用户数据库的网站,我想让他们在他们的个人资料页面上显示他们的当前推特消息(如果他们有一个Twitter帐户)。
经过搜索,我看到了这个工具:http://juitter.com它看起来有点复杂,正好满足了我的需求。
我正在使用Rails。你有没有一个尽可能简单的工具可以做到这一点?
谢谢你D
发布于 2010-01-12 18:48:54
您可以查看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调用获得最后一条tweet:
<!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>
发布于 2010-01-12 18:47:37
看一看twitter的精华。它使用起来非常简单。
发布于 2012-01-30 15:23:00
mikus的回答对我不起作用,我得到了
XMLHttpRequest无法加载 。Access--Allow-Origin.不允许使用原始控制
我在Accessing JSON service from localhost or file://中找到了答案
绕过同源策略的一种方法是加载JSONP而不是JSON。您可以使用twitter API和jQuery来完成此操作,您只需添加"callback=?“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>
https://stackoverflow.com/questions/2048253
复制相似问题