コレまで使用していたtweepyがapi1.1に対応していないということでコチラの導入を
https://bitbucket.org/sakito/tweepy
おそらく2013/02/12時点ではeasy_installやpipではなく人力でになるような、多分。。。
Downloadsにある最新版を解凍して出来るtweepy2を丸ごとtweepyと同じ階層にcp -Rでコピーしただけで動きました。
hoge.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
from oauth2 import Client, Consumer, Token
import tweepy2
consumer_key = ""
consumer_secret = ""
user_key = "-"
user_secret = ""
auth = tweepy2.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(user_key, user_secret)
client = Client(Consumer(consumer_key, consumer_secret),
Token(user_key, user_secret))
api = tweepy2.API(auth)
今までtweepyと書いていた箇所をtweepy2にしただけでOAuthトークンは問題ないようでした。
tweet.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import pywapi
from urllib import urlencode
import datetime
import hoge
result = pywapi.get_weather_from_yahoo('JAXX0043', 'metric')
time = datetime.datetime.now()
ms = time.microsecond
twit = u"@hoge 熊本の現在から今夜くらいの天候は" + result['forecasts'][0]['text'] + u" 気温は最高" \
+ result['forecasts'][0]['high'] \
+ u"で最低が" + result['forecasts'][0]['low'] + u"くらい。" + " #fkdr " + str(ms)
weth = twit.encode("utf-8")
hoge.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': weth}))
こちらは変更は最終行の投稿部分のurlが変わっただけで動きました。
ウチはtweepy2導入と投稿を投げるurl変更でほぼほぼ問題無さそう。
TLやフォロー・フォロワー取得して色々やってる人の場合は何か障害出てくるかもしれませんが。。。。