2012年6月7日木曜日

WebAPIの利用(1)

twitter public timeline検索APIの利用
表示例

LINK

取得されるXMLのサンプル(一部抜粋)
<?xml version="1.0" encoding="utf-8"?>
<rss>
 <channel>
   <item>
    <title>@Copa3 ありがとうございます。横浜ですかそりゃ、とおくていけませんわ。</title>
    <link>http://twitter.com/sendaimo/statuses/137026307379822592</link>
    <description>@&lt;a class=" " href="http://twitter.com/Copa3"&gt;Copa3&lt;/a&gt; ありがとうございます。&lt;em&gt;横浜&lt;/em&gt;ですかそりゃ、とおくていけませんわ。</description>
    <pubDate>Thu, 17 Nov 2011 04:36:32 +0000</pubDate>
    <guid>http://twitter.com/sendaimo/statuses/137026307379822592</guid>
    <author>sendaimo@twitter.com (Kimiaki Nagase)</author>
    <media:content type="image/jpg" height="48" width="48" url="http://a0.twimg.com/profile_images/825361762/saxbobo02_normal.gif" xmlns:media="http://search.yahoo.com/mrss/" />
    <google:image_link xmlns:google="http://base.google.com/ns/1.0">http://a0.twimg.com/profile_images/825361762/saxbobo02_normal.gif</google:image_link>
    <twitter:metadata xmlns:twitter="http://api.twitter.com/">
     <twitter:result_type>recent</twitter:result_type>
    </twitter:metadata>
   </item>
 </channel>
</rss>

twitter_timeline.php
<?php
 $word = "横浜";
 $url = "http://search.twitter.com/search.rss?q=".$word;

 $rss = simplexml_load_file($url);

 $title = $rss->channel->item->title;
 $link = $rss->channel->item->link;
 $description = $rss->channel->item->description;
 $pubDate = $rss->channel->item->pubDate;
 $author = $rss->channel->item->author;

print<<<EOF
 <html>
 <head>
 <title>twitter sample</title>
 </head>
 <body>
EOF;

 print "title : ".$title."<br />";
 print "link : ".$link."<br />";
 print "description : ".$description."<br />";
 print "pubDate : ".$pubDate."<br />";
 print "author : ".$author."<br />";
 print "image_link : ".$iage_link."<br />";

print<<<EOF
 </body>
 </html>
EOF;
?>

0 件のコメント: