Tweepy应用引擎示例引发401异常



我在这里使用tweepy google应用程序引擎示例作为我的应用程序的基础:https://github.com/tweepy/examples/tree/master/appengine

get_authorization_url()方法触发401未授权异常。

template.render('oauth_example/main.html', {
                "authurl": auth.get_authorization_url(),
                "request_token": auth.request_token
                })

在控制台我得到:

TweepError: HTTP Error 401: Unauthorized

使用python解释器中的库工作得很好:

进口tweepy

auth = tweepy。OAuthHandler (CONSUMER_KEY CONSUMER_SECRET)

打印auth.get_authorization_url ()

打印出一个有效的身份验证url。但是,示例中MainPage处理程序开头的相同代码会失败。

class MainPage(RequestHandler):
  def get(self):
    # Build a new oauth handler and display authorization url to user.
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    print auth.get_authorization_url() # EXCEPTION 401 Unauthorized

任何帮助都会很感激。

找到解决方案

除了用回调URL更新tweepy中的回调之外,还可以在dev.twitter.com的app section中更新。

你需要给正确的回调URL而

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK)

最新更新