2009/10/30
twitter API / Retweet の仕様が・・・
List機能を調べていて気付いたんですけど、APIで返ってくるRetweetに関するXMLの構造がドラフトで公開されている情報と微妙に異なっている模様です。
まず、ドラフトのページでサンプルとして挙げられているソースをXMLスキーマとして図に示すと次のようになります。

ところが実際は、違った構造に変わっていました。
次のソースは、「/statuses/home_timeline」を使用して実際に取得したものです。
<?xml version="1.0" encoding="UTF-8"?>これを同じくXMLスキーマで図示すると下図のようになります。
<statuses type="array">
<status>
<created_at>Thu Oct 29 16:48:39 +0000 2009</created_at>
<id>5263226419</id>
<text>RT @kevinhendricks: The best way to avoid DM phishing on
Twitter? Don't automatically follow everyone who follows you.</text>
<source>web</source>
<truncated>false</truncated>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<favorited>false</favorited>
<in_reply_to_screen_name/>
<retweeted_status>
<created_at>Thu Oct 29 16:20:19 +0000 2009</created_at>
<id>5262542304</id>
<text>The best way to avoid DM phishing on Twitter? Don't automatically
follow everyone who follows you.</text>
<source><a href="http://www.hootsuite.com"
rel="nofollow">HootSuite</a></source>
<truncated>false</truncated>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<favorited>false</favorited>
<in_reply_to_screen_name/>
<user>
<id>6459792</id>
<name>Kevin D. Hendricks</name>
<screen_name>kevinhendricks</screen_name>
<location>St. Paul, MN</location>
<description>Work: Writer/editor, content guru & Internet
geek. Family: Husband, dad, dogs. Distractions: Public art, U2 &
yo-yos. Needs: Love, hope & grace.</description>
<profile_image_url>
http://a3.twimg.com/profile_images/489534755/twitter_normal.jpg
</profile_image_url>
<url>http://www.kevindhendricks.com</url>
<protected>false</protected>
<followers_count>1171</followers_count>
<profile_background_color>9ae4e8</profile_background_color>
<profile_text_color>000000</profile_text_color>
<profile_link_color>0000ff</profile_link_color>
<profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
<profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
<friends_count>369</friends_count>
<created_at>Thu May 31 02:36:09 +0000 2007</created_at>
<favourites_count>338</favourites_count>
<utc_offset>-21600</utc_offset>
<time_zone>Central Time (US & Canada)</time_zone>
<profile_background_image_url>
http://a3.twimg.com/profile_background_images/
4439633/background2.gif</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<statuses_count>5336</statuses_count>
<notifications/>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following/>
</user>
<geo/>
</retweeted_status>
<user>
<id>20</id>
<name>Evan Williams</name>
<screen_name>ev</screen_name>
<location>San Francisco, CA, US</location>
<description>CEO of Twitter</description>
<profile_image_url>
http://a1.twimg.com/profile_images/66154838/ev-sky_bigger_normal.jpg
</profile_image_url>
<url>http://evhead.com</url>
<protected>false</protected>
<followers_count>1176029</followers_count>
<profile_background_color>C0DEED</profile_background_color>
<profile_text_color>301630</profile_text_color>
<profile_link_color>b30000</profile_link_color>
<profile_sidebar_fill_color>e8e2c5</profile_sidebar_fill_color>
<profile_sidebar_border_color>6f7578</profile_sidebar_border_color>
<friends_count>915</friends_count>
<created_at>Tue Mar 21 21:02:31 +0000 2006</created_at>
<favourites_count>1224</favourites_count>
<utc_offset>-28800</utc_offset>
<time_zone>Pacific Time (US & Canada)</time_zone>
<profile_background_image_url>
http://s.twimg.com/a/1256778767/images/themes/theme15/bg.png
</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<statuses_count>4691</statuses_count>
<notifications/>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following/>
</user>
<geo/>
</status>
・・・ 省略
</statuses>
まず、要素名「retweet_details」が「retweeted_status」に変わった模様です。

更に、その下位の要素が「/statues/status」配下の要素と相似関係となりその殆どが同名で参照するように変わっています。
例えば、ステータスidが以前は「retweet_id」でしたが「id」に、作成時刻が以前は「retweeted_at」でしたが「created_at」に、ユーザの情報が以前は、「retweeting_user」でしたが、「user」に、要素の並びも同じになったといっても良いでしょう。

これによって、ユーザ情報をあらわす「/statuses/status/user」や「/statuses/status/user/retweeted_status/user」は、いずれもスキーマ上の同じグローバルな「user」要素を参照できるようになりましたし、並んでいる他の要素のメンバーも同じになることによってコーディングも楽になったと言って良いでしょう。
関連を表す情報として、「/statuses/status/id」と「/statuses/status/retweeted_status/id」を記録することにより、Retweetのスレッド表示などが可能になりそうです。
ちなみに、下記の新しく追加される予定の仕様については、現状使うことができませんでした。
(もう間もなくでしょう・・・?)
だんだんと、楽しくなってきますねぇ・・・!
- statuses/retweeted_by_me
- statuses/retweeted_to_me
- statuses/retweets_of_me
- Category(s)
