blog/content/post/2011/05/15/2011-05-15-00001492.md

100 lines
6.5 KiB
Markdown

---
title: http postがなぜか出来ない
author: kazu634
date: 2011-05-15
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:5429;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- gauche
- Lisp
---
<div class="section">
<p>
Mixi Voiceに投稿するプログラミを作成中なのですが、以下の curl のコマンドだとうまく投稿できます:
</p>
<pre class="syntax-highlight">
$ curl <span class="synSpecial">-H</span> <span class="synStatement">&#34;</span><span class="synConstant">Content-Type: application/x-www-form-urlencoded</span><span class="synStatement">&#34;</span> <span class="synSpecial">-d</span> <span class="synStatement">status=&#34;</span><span class="synConstant">Hello world</span><span class="synStatement">&#34;</span> <span class="synSpecial">-d</span> <span class="synIdentifier">oauth_token</span>=<span class="synStatement">&#60;</span>oauthトークン<span class="synStatement">&#62;</span> http://api.mixi-platform.com/<span class="synConstant">2</span>/voice/statuses/update
<span class="synSpecial">{</span><span class="synStatement">&#34;</span><span class="synConstant">created_at</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">Sun May 15 13:45:14 +0000 2011</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">favorited</span><span class="synStatement">&#34;</span>:<span class="synStatement">false</span>,<span class="synStatement">&#34;</span><span class="synConstant">text</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">Hello world</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">user</span><span class="synStatement">&#34;</span>:<span class="synSpecial">{</span><span class="synStatement">&#34;</span><span class="synConstant">url</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">http://mixi.jp/show_friend.pl?uid=4ncdm68fwm56j</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">profile_image_url</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">http://profile.img.mixi.jp/photo/user/4ncdm68fwm56j_94665934418.jpg</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">id</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">4ncdm68fwm56j</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">screen_name</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">simoom634</span><span class="synStatement">&#34;</span><span class="synSpecial">}</span>,<span class="synStatement">&#34;</span><span class="synConstant">id</span><span class="synStatement">&#34;</span>:<span class="synStatement">&#34;</span><span class="synConstant">4ncdm68fwm56j-20110515224514</span><span class="synStatement">&#34;</span>,<span class="synStatement">&#34;</span><span class="synConstant">favorite_count</span><span class="synStatement">&#34;</span>:<span class="synConstant"></span>,<span class="synStatement">&#34;</span><span class="synConstant">reply_count</span><span class="synStatement">&#34;</span>:<span class="synConstant"></span><span class="synSpecial">}</span>
</pre>
<p>
これと同じように HTTP post するコマンドを gauche で書きました:
</p>
<pre class="syntax-highlight">
<span class="synSpecial">(</span>receive <span class="synSpecial">(</span>status header body<span class="synSpecial">)</span>
<span class="synSpecial">(</span>http-post <span class="synConstant">&#34;api.mixi-platform.com&#34;</span>
<span class="synConstant">&#34;/2/voice/statuses/update&#34;</span>
<span class="synSpecial">'((</span><span class="synConstant">&#34;status&#34;</span> :value <span class="synConstant">&#34;Hello world.&#34;</span> :content-type <span class="synConstant">&#34;application/x-www-form-urlencoded&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synConstant">&#34;oauth_token&#34;</span>&#60;oauthトークン&#62;<span class="synSpecial">)</span>
<span class="synSpecial">)</span>
<span class="synSpecial">(</span>display status<span class="synSpecial">)</span>
<span class="synSpecial">(</span>display body<span class="synSpecial">))</span>
</pre>
<p>
でも、これだとステータスコードに 400 が帰ってきます。なんでだろう?
</p>
<p>
ちなみに、Mixi のドキュメントにはこんな感じで書かれています:
</p>
<blockquote>
<p>
つぶやきを新規に投稿するためのURIは以下となります。2種類ありますが、どちらも結果は同じです。
</p>
<ul>
<li>
POST <a href="http://api.mixi-platform.com/2/voice/statuses/update" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://api.mixi-platform.com/2/voice/statuses/update', 'http://api.mixi-platform.com/2/voice/statuses/update');" target="_blank">http://api.mixi-platform.com/2/voice/statuses/update</a>
</li>
<li>
POST <a href="http://api.mixi-platform.com/2/voice/statuses" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://api.mixi-platform.com/2/voice/statuses', 'http://api.mixi-platform.com/2/voice/statuses');" target="_blank">http://api.mixi-platform.com/2/voice/statuses</a>
</li>
</ul>
<p>
リクエストボディとして、つぶやきの本文をapplication/x-www-form-urlencoded形式で指定します。
</p>
<blockquote>
<p>
status=%E3%81%A4%E3%81%B6%E3%82%84%E3%81%8D%E3%81%AE%E6%9C%AC%E6%96%87
</p>
</blockquote>
<table>
<tr>
<td>
パラメータ名
</td>
<td>
指定する値
</td>
</tr>
<tr>
<td>
status
</td>
<td>
つぶやきの本文
</td>
</tr>
</table>
<p>
statusパラメータに指定する文字列の文字コードはUTF-8とし、それをURIエンコードした結果を指定します。
</p>
</blockquote>
<p>
何か見落としているのかな?
</p>
</div>