tweepyで2-legged OAuth
twitter連携するアプリケーションを書いてみようかと思ってちょっと試してみたのでメモ。
tweepyを選んだのはこのページで強調されてたのでメジャーなのかなあと思ったから。
https://dev.twitter.com/docs/twitter-libraries
コード
アプリケーションの登録だとかaccess tokenの発行だとか諸々の手続きを先にやっておく。
>>> import tweepy >>> consumer_key = "xxxxxxxxxxxxxxxxxxx" >>> consumer_secret = "xxxxxxxxxxxxxxxxxxx" >>> access_token = "xxxxxxxxxxxxxxxxxxx" >>> access_seecret = "xxxxxxxxxxxxxxxxxxx" >>> handle = tweepy.OAuthHandler(concumer_key, concumer_secret) >>> handle.set_access_token(access_token, access_secret) >>> api = tweepy.API(handle) >>> api.update_status("tweet from script") <tweepy.models.Status at 0xa8de8cc>
tweet from script
参考URL
ほぼここのコードを利用。
http://blog.kzfmix.com/entry/1266577646
これに引っかかったのでntpdate入れた。
http://d.hatena.ne.jp/jonki/20110211