2010-01-12 4 views
2

나는 사용자 데이터베이스가있는 웹 사이트를 가지고 있으며, 트위터 계정이 있으면 자신의 프로필 페이지에 현재 트윗 메시지를 표시 할 수 있습니다.웹 페이지에서 마지막 트윗을 공유하십시오.

검색 후, 나는이 도구를 보았습니다 : http://juitter.com 그것은 내 요구에 조금 복잡해 보입니다.

저는 Rails를 사용하고 있습니다. 가능한 한 간단하게 도구를 알고 있습니까?

는 D

답변

4

당신은 트위터 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

+2

페이지 소스를보세요. 사용자 ID에 대한 몇 가지 참조 사항이 있습니다 (예 : 'http://twitter.com/statuses/user_timeline/20104013.rss'. 나는이 문제를 심층적으로 조사하지는 않았지만 사용자가 트위터 ID를 직접 제공하거나 페이지를 한 번 긁어서 사용자 ID를 얻은 다음 서버에 로컬로 저장하도록 제안합니다. 그것은 단지 빠른 대답입니다. 당신은 이것을 구현하는 더 좋은 방법을 찾을 수 있습니다 .. – miku

0

twitter 보석 번 봐 주셔서 감사합니다. 그것은 사용하기 매우 간단합니다.

+0

존이 보석에 감사드립니다. – Denis

0

mikus 대답하지 않았다 나를 위해 일하는, 내가있어

XMLHttpR 승점은 http://twitter.com/users/show/ditact.json을로드 할 수 없습니다. Origin http://mydomain.com은 Access-Control-Allow-Origin에서 허용되지 않습니다.

나는 같은 원본 정책 해결하기 위해 Accessing JSON service from localhost or file://

한 가지 방법에서 답 JSONP 대신 JSON을로드하는 것입니다 발견했다. 트위터 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>