Oauth2 Python 封装 Twitter 无需输入 PIN 验证

发布于 2024-12-09 18:47:48 字数 1232 浏览 0 评论 0原文

我正在尝试设置此 Twitter 授权,而无需用户在屏幕中输入 PIN 码,但我无法正确设置,我总是被引导输入 PIN 码。尝试使用并遵循此包 https://github.com/simplegeo/python-oauth2

这是我当前的代码

env = Environment(loader = PackageLoader('buzzient','tmpl'))
template = env.get_template('authtwitter.html')
tmpldict = {}

#SETUP TWITTER AUTHORIZATION OBJECT
consumer_key = '######################'
consumer_secret = '##############################'
request_token_url = 'http://twitter.com/oauth/request_token'
access_token_url = 'http://twitter.com/oauth/access_token'
authorize_url = 'http://twitter.com/oauth/authenticate'

consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)

#get request token
resp, content = client.request(request_token_url, "GET")
if resp['status'] != '200':
        raise Exception("Invalid Response %s." %resp['status'])

request_token = dict(urlparse.parse_qsl(content))

tmpldict['twitauthurl'] = "%s?oauth_token=%s" % ( authorize_url, request_token['oauth_token'] )
qargs=buzzientlib.urlparse_qs(self.request.url,True,False)

t = template.render(tmpldict)
self.response_body = str(t)

该模板仅包含指向 twitauthurl 的链接

I am trying to setup this Twitter authorization without having the user to enter the pin in our screen but I am having trouble getting the correct setup I am always directed to enter the PIN. trying to use and follow this package https://github.com/simplegeo/python-oauth2

Here is my current code

env = Environment(loader = PackageLoader('buzzient','tmpl'))
template = env.get_template('authtwitter.html')
tmpldict = {}

#SETUP TWITTER AUTHORIZATION OBJECT
consumer_key = '######################'
consumer_secret = '##############################'
request_token_url = 'http://twitter.com/oauth/request_token'
access_token_url = 'http://twitter.com/oauth/access_token'
authorize_url = 'http://twitter.com/oauth/authenticate'

consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)

#get request token
resp, content = client.request(request_token_url, "GET")
if resp['status'] != '200':
        raise Exception("Invalid Response %s." %resp['status'])

request_token = dict(urlparse.parse_qsl(content))

tmpldict['twitauthurl'] = "%s?oauth_token=%s" % ( authorize_url, request_token['oauth_token'] )
qargs=buzzientlib.urlparse_qs(self.request.url,True,False)

t = template.render(tmpldict)
self.response_body = str(t)

The template just includes a link to twitauthurl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-12-16 18:47:48

将包切换到 Tweepy 并按照此示例

http://packages.python.org/tweepy/html /auth_tutorial.html

Switched packages to Tweepy and followed this example

http://packages.python.org/tweepy/html/auth_tutorial.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文