Authentication with twython

2019-06-13 16:45发布

app_key=" "
app_secret=" "

twitter = Twython(app_key=app_key,
app_secret=app_secret)
auth_props = twitter.get_authentication_tokens()
oauth_token = auth_props['oauth_token']
oauth_token_secret = auth_props['auth_url']

print 'Connect to Twitter via: %s' % auth_props['auth_url']
print twitter.search(q='python')

I have the above twython code and the authentication is not working.

I am getting,

TwythonAuthError: Twitter API returned a 400 (Bad Request), Bad Authentication data at print twitter.search(q='python')

Do I need a callback url? I am just starting a project, I do not have a dedicated website for it.

1条回答
Lonely孤独者°
2楼-- · 2019-06-13 17:25

I am a collaborator on the Twython project.

Please follow these steps:

  1. https://github.com/ryanmcgrath/twython#authorization-url
  2. https://github.com/ryanmcgrath/twython#handling-the-callback

Save your oauth token and secret

then try

app_key = 'YOUR_APP_KEY'
app_secret = 'YOUR_APP_SECRET'
oauth_token = auth_tokens['oauth_token'] # from step 2
oauth_token_secret = auth_tokens['oauth_token_secret'] # from step 2

t = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
t.search(q='python')
查看更多
登录 后发表回答