使用twython进行身份验证 [英] Authentication with twython

查看:129
本文介绍了使用twython进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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')

我具有上面的twython代码,并且身份验证不起作用.

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

我得到了

TwythonAuthError:Twitter API返回了400(错误请求),错误的身份验证数据 在打印twitter.search(q ='python')

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.

推荐答案

我是Twython项目的合作伙伴.

I am a collaborator on the Twython project.

请按照以下步骤操作:

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

保存您的oauth令牌和机密

Save your oauth token and secret

然后尝试

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')

这篇关于使用twython进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆