我尝试使用 Tweepy 和 Flask,但我似乎得到了请求令牌。
这是失败的代码。
CONSUMER_TOKEN='fill this out'
CONSUMER_SECRET='and this'
CALLBACK_URL = 'http://localhost:5000/verify'
session = dict()
db = dict() #you can save these values to a database
@app.route("/")
def send_token():
auth = tweepy.OAuthHandler(CONSUMER_TOKEN,
CONSUMER_SECRET,
CALLBACK_URL)
try:
#get the request tokens
redirect_url= auth.get_authorization_url()
session['request_token']= (auth.request_token.key,
auth.request_token.secret)
except tweepy.TweepError:
print 'Error! Failed to get request token'
#this is twitter's url for authentication
return flask.redirect(redirect_url)
它来自这个github 项目。当然,我替换了消费者令牌/秘密。
为什么 auth.get_authorization_url() 失败?
谢谢你。
完整的日志是这个
* Running on http://127.0.0.1:5000/
Error! Failed to get request token
127.0.0.1 - - [20/Nov/2012 22:54:28] "GET / HTTP/1.1" 500 -
127.0.0.1 - - [20/Nov/2012 22:54:29] "GET /favicon.ico HTTP/1.1" 404 -