Sample Twitter Search with google feed api:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function getTwitterSearch(q, id, callbackfunction)
{
q = encodeURI(q);
id = encodeURI(id);
var feed = new google.feeds.Feed("http://search.twitter.com/search.atom?q="+q+"&rpp=100&show_user=true&since_id="+id); feed.setNumEntries(10); feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT); feed.load(function(result) { if (!result.error) { var ava = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "link"); //google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://search.yahoo.com/mrss/", "content"); ; var imageA = new Array(); j=0; for (var i = 0; i < ava.length; i++) { if(ava[i].getAttribute('rel')=="image") { imageA[j]=ava[i].getAttribute('href'); j++; } } var tA = new Array(result.feed.entries.length); for (var i = 0; i < result.feed.entries.length; i++) { var twitterMessage = new Object; entry = result.feed.entries[i]; temp = entry.link.split("/"); twitterMessage = { text: entry.title, link: entry.link, date: entry.publishedDate, user: entry.author, statusid: temp[5], image: imageA[i] }; tA[i]=twitterMessage; } callbackfunction(tA); } }); } function reverseSimpleWrite(tA) { tA.reverse(); var container = document.getElementById("feed"); for (var i = 0; i < tA.length; i++) { var entry = tA[i]; var div = document.createElement("li"); div.innerHTML="<img src='"+entry.image+"' width='48' height='48' > "+entry.image+"<br>user: "+entry.user+"<br>date: "+entry.date+"<br> text: "+entry.text+" <br> link: <a href='"+entry.link+"'>"+entry.link+"</a><br> statusid: "+entry.statusid+"<br><br>"; container.appendChild(div); } } google.setOnLoadCallback(function(){ getTwitterSearch("iphone", 0, reverseSimpleWrite); } ); </script>
See the original code and sample here:
http://www.facesaerch.com/widget/twitterjs.php
No comments:
Post a Comment