2008-05-14
python-twitterまとめ 〜導入まで
python-twitterというものを使うと簡単にTwitterのAPIなどで遊べると噂に聞き、導入してみました。
まずは必要なものをダウンロードする
- python-twitter - Google Codeで、python-twitter-0.5.tar.gzをダウンロードする。
- Python Package Index : simplejson 1.9.1で、simplejsonをダウンロードする。このモジュールがないと動かない。
インストールするよ!
- simplejson編
これでお手軽にTwitterのデータをPythonでいじれるようになります!
せっかくだから少し遊ぶ
python-twitter - Google Codeの下の方とか、ドキュメントPython: module twitterを見ながらやってみました。ただのコピペだけど><
>>> import twitter >>> api = twitter.Api("ユーザー名", "パスワード") >>> status = api.PostUpdate("Hello, python-twitter!!")
これだけでTwitterに投稿できます!
http://twitter.com/ama_ch/statuses/810947484
あ、これで投稿できるのはascii文字だけみたいです。日本語で投稿しようとしたらこんなエラーでた><
>>> status = api.PostUpdate("python-twitterから投稿してるよ!")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twitter.py", line 1054, in PostUpdate
json = self._FetchUrl(url, post_data=data)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twitter.py", line 1418, in _FetchUrl
encoded_post_data = self._EncodePostData(post_data)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twitter.py", line 1391, in _EncodePostData
return urllib.urlencode(dict([(k, self._Encode(v)) for k, v in post_data.items()]))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twitter.py", line 1356, in _Encode
return unicode(s).encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 14: ordinal not in range(128)
5/18追記
日本語で投稿できました。u"文字列"でユニコード指定してあげるだけだった><
>>> import twitter >>> api = twitter.Api("ユーザー名", "パスワード") >>> status = api.PostUpdate(u"てすとー")
http://twitter.com/ama_ch/statuses/813909605
今日はここまで
近々これでいろいろ遊んでみます。明日にはみんPy終わらせたい。
トラックバック - http://d.hatena.ne.jp/ama-ch/20080514/1210757894
- [Python][Mercurial]巡回
- PythonでTwitter
- YAMAGUCHI::weblog - python-twitterをMacOS X Tigerで動かしてみる
- PythonでTwitter Bot
- ます素子 - PythonでTwitter Botを作る(導入)
- 勉強日記かもしれない - 6月5日 python-twitter
- Number6の「あーあ、俺に狐の嫁さんできねぇかなぁ!!」 - python-...
- yu_ya memo - 明日をつぶやくbot
- 未来は僕以外の手の中 - pythonでTwitter botを作ってみる
- さらまんだりん - PythonでWebプログラミング(のようなもの)
- えびし日記 - Python2.7を使ってみる
リンク元
- 487 http://www.google.co.jp/search?q=Python+Twitter&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 330 http://www.google.co.jp/search?q=python+twitter&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a
- 321 http://creco.net/2009/04/13/softalk_tweet_timeline_of_twitter/
- 287 http://dotred5.blogspot.com/2008/05/pythontwitter.html
- 245 http://www.google.co.jp/search?q=python-twitter&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 195 http://www.google.co.jp/search?sourceid=chrome&ie=UTF-8&q=python-twitter
- 157 http://www.google.co.jp/url?sa=t&rct=j&q=python twitter&source=web&cd=4&sqi=2&ved=0CEUQFjAD&url=http://d.hatena.ne.jp/ama-ch/20080514/1210757894&ei=ZzuFTo-wC8zOmAWyluCxBA&usg=AFQjCNEDerQquoExeWWc0H4jTqAu6g2Cyw&sig2=SKdkMW-8CZZC_HpKqUpVmA
- 151 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=39b&q=Python 導入&btnG=検索&lr=lang_ja
- 122 http://www.google.co.jp/search?q=python-twitter&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:unofficial&client=firefox-a
- 113 http://www.google.co.jp/search?aq=f&sourceid=chrome&ie=UTF-8&q=python+twitter
