151 lines
12 KiB
Markdown
151 lines
12 KiB
Markdown
---
|
|
title: Tumblr の API Gauche でたたく
|
|
author: kazu634
|
|
date: 2010-09-16
|
|
url: /2010/09/16/_1576/
|
|
wordtwit_post_info:
|
|
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5347;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|
categories:
|
|
- gauche
|
|
- Lisp
|
|
|
|
---
|
|
<div class="section">
|
|
<p>
|
|
Tumblr で like したものを RSS にしたくて、 Tumblr API を Gauche でたたくプログラムを作成中です。 Shiro さんの net-twitter を参考にして、とりあえず XML を取得するところまでできました。
|
|
</p>
|
|
|
|
<p>
|
|
ちなみに API のドキュメントはこれです:
|
|
</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<a href="http://www.tumblr.com/docs/en/api" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.tumblr.com/docs/en/api', 'API | Tumblr');" target="_blank">API | Tumblr</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>
|
|
ソース
|
|
</h4>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">;;; Tumblrへのアクセス用</span>
|
|
<span class="synSpecial">(</span>use rfc.http<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>use gauche.charconv<span class="synSpecial">)</span>
|
|
<span class="synComment">;;; Tumblrで自分のページを取得するために必要となるパラメータ</span>
|
|
<span class="synComment">;;; APIのドキュメントをそのまま書き下す</span>
|
|
<span class="synSpecial">(</span>define-class <tumblr-simple-read> <span class="synSpecial">()</span>
|
|
<span class="synSpecial">((</span>start :init-keyword <span class="synType">:start</span> :init-value <span class="synConstant"></span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>num :init-keyword :num :init-value <span class="synConstant">20</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">type</span> :init-keyword <span class="synType">:type</span> :init-value <span class="synConstant">""</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>id :init-keyword :id :init-value <span class="synConstant">""</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>filter :init-keyword :filter :init-value <span class="synConstant">""</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>tagged :init-keyword :tagged :init-value <span class="synConstant">""</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">search</span> :init-keyword :search :init-value <span class="synConstant">""</span><span class="synSpecial">)))</span>
|
|
<span class="synComment">;;; Tumblrで自分が like したものを取得するために必要となるパラメータ</span>
|
|
<span class="synComment">;;; APIのドキュメントをそのまま書き下す</span>
|
|
<span class="synSpecial">(</span>define-class <tumblr-liked-posts> <span class="synSpecial">()</span>
|
|
<span class="synSpecial">((</span>email :init-keyword :email :init-value <span class="synConstant">"example@example.com"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>password :init-keyword :password :init-value <span class="synConstant">"password"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>start :init-keyword <span class="synType">:start</span> :init-value <span class="synConstant"></span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>num :init-keyword :num :init-value <span class="synConstant">20</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>filter :init-keyword :filter :init-value <span class="synConstant">""</span><span class="synSpecial">)))</span>
|
|
<span class="synComment">;;; <tumblr-simple-read>をリストにする</span>
|
|
<span class="synComment">;;; リストにすると、 http-compose-query を使用して</span>
|
|
<span class="synComment">;;; queryストリングを簡単に生成できる</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>make-tumblr-simple-read-param-list params<span class="synSpecial">)</span>
|
|
<span class="synPreProc">`(</span><span class="synSpecial">(</span>start ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">start</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>num ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">num</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">type</span> ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">type</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>id ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">id</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>filter ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">filter</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>tagged ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">tagged</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">search</span> ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">search</span><span class="synSpecial">))</span><span class="synPreProc">)</span><span class="synSpecial">)</span>
|
|
<span class="synComment">;;; <tumblr-liked-posts>をリストにする</span>
|
|
<span class="synComment">;;; リストにすると、 http-compose-query を使用して</span>
|
|
<span class="synComment">;;; http-post が post するデータを簡単に生成できる</span>
|
|
<span class="synSpecial">(</span>define <span class="synSpecial">(</span>make-liked-post-list params<span class="synSpecial">)</span>
|
|
<span class="synPreProc">`(</span><span class="synSpecial">(</span>email ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">email</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>password ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">password</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>start ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">start</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>num ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">num</span><span class="synSpecial">))</span>
|
|
<span class="synSpecial">(</span>filter ,<span class="synSpecial">(</span>ref params <span class="synSpecial">'</span><span class="synIdentifier">filter</span><span class="synSpecial">))</span><span class="synPreProc">)</span><span class="synSpecial">)</span>
|
|
</pre>
|
|
|
|
<h4>
|
|
実行例
|
|
</h4>
|
|
|
|
<p>
|
|
下の式を評価すれば、 XML を取得できます:
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">;;; テスト</span>
|
|
<span class="synSpecial">(</span>receive <span class="synSpecial">(</span>status-code http-header contents<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>http-get <span class="synConstant">"kazu634.tumblr.com"</span>
|
|
<span class="synSpecial">(</span>http-compose-query
|
|
<span class="synConstant">"/api/read"</span>
|
|
<span class="synSpecial">(</span>make-tumblr-simple-read-param-list
|
|
<span class="synSpecial">(</span>make <tumblr-simple-read>
|
|
<span class="synType">:type</span> <span class="synConstant">"photo"</span><span class="synSpecial">))))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span><span class="synStatement">equal</span>? status-code <span class="synConstant">"200"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>ces-convert contents <span class="synConstant">"*JP"</span><span class="synSpecial">)</span>
|
|
#f<span class="synSpecial">))</span>
|
|
<span class="synComment">;;; テスト</span>
|
|
<span class="synSpecial">(</span>receive <span class="synSpecial">(</span>status-code http-header contents<span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>http-post <span class="synConstant">"yourname.tumblr.com"</span>
|
|
<span class="synConstant">"/api/likes"</span>
|
|
<span class="synSpecial">(</span>make-liked-post-list
|
|
<span class="synSpecial">(</span>make <tumblr-liked-posts>
|
|
:email <span class="synConstant">"Your E-mail address"</span>
|
|
:password <span class="synConstant">"Your password"</span><span class="synSpecial">)))</span>
|
|
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span><span class="synStatement">equal</span>? status-code <span class="synConstant">"200"</span><span class="synSpecial">)</span>
|
|
<span class="synSpecial">(</span>ces-convert contents <span class="synConstant">"*JP"</span><span class="synSpecial">)</span>
|
|
#f<span class="synSpecial">))</span>
|
|
</pre>
|
|
|
|
<h4>
|
|
ToDo
|
|
</h4>
|
|
|
|
<p>
|
|
あとは、これを SXML に変換してから、RSSを生成すればよいわけですな。
|
|
</p>
|
|
|
|
<div class="hatena-asin-detail">
|
|
<a href="http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv', '');"><img src="https://images-na.ssl-images-amazon.com/images/I/51Exg14b4uL._SL160_.jpg" class="hatena-asin-detail-image" alt="プログラミングGauche" title="プログラミングGauche" /></a></p>
|
|
|
|
<div class="hatena-asin-detail-info">
|
|
<p class="hatena-asin-detail-title">
|
|
<a href="http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4873113482/?tag=hatena_st1-22&ascsubtag=d-7ibv', 'プログラミングGauche');">プログラミングGauche</a>
|
|
</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">作者:</span> <a href="http://d.hatena.ne.jp/keyword/Kahua%A5%D7%A5%ED%A5%B8%A5%A7%A5%AF%A5%C8" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/Kahua%A5%D7%A5%ED%A5%B8%A5%A7%A5%AF%A5%C8', 'Kahuaプロジェクト');" class="keyword">Kahuaプロジェクト</a>,<a href="http://d.hatena.ne.jp/keyword/%C0%EE%B9%E7%BB%CB%CF%AF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C0%EE%B9%E7%BB%CB%CF%AF', '川合史朗');" class="keyword">川合史朗</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">出版社/メーカー:</span> <a href="http://d.hatena.ne.jp/keyword/%A5%AA%A5%E9%A5%A4%A5%EA%A1%BC%A5%B8%A5%E3%A5%D1%A5%F3" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%AA%A5%E9%A5%A4%A5%EA%A1%BC%A5%B8%A5%E3%A5%D1%A5%F3', 'オライリージャパン');" class="keyword">オライリージャパン</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">発売日:</span> 2008/03/14
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">メディア:</span> 大型本
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">購入</span>: 22人 <span class="hatena-asin-detail-label">クリック</span>: 713回
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/asin/4873113482" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/4873113482', 'この商品を含むブログ (272件) を見る');" target="_blank">この商品を含むブログ (272件) を見る</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="hatena-asin-detail-foot">
|
|
</div>
|
|
</div>
|
|
</div>
|