本文整理汇总了Python中oauth.oauth.OAuthRequest.to_url方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthRequest.to_url方法的具体用法?Python OAuthRequest.to_url怎么用?Python OAuthRequest.to_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth.oauth.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.to_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_auth
# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import to_url [as 别名]
def start_auth(request, fail_redirect='/account/other_services/'):
consumer = OAuthConsumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
# Request the OAuth Token
req = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_REQUEST_TOKEN_URL,
parameters={}, http_method="POST")
req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
try:
res = urllib.urlopen(TWITTER_REQUEST_TOKEN_URL, req.to_postdata())
requestToken = OAuthToken.from_string(res.read())
# Authorise the OAuth Token
oauth_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_AUTHORIZE_URL,
parameters={}, http_method="GET", token=requestToken)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, requestToken)
return HttpResponseRedirect(oauth_request.to_url())
except IOError:
request.user.message_set.create(
message=ugettext(u"Twitter authorization failed.")
)
return HttpResponseRedirect(fail_redirect)
示例2: get_credentials_from_request
# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import to_url [as 别名]
def get_credentials_from_request(request):
token = OAuthToken(request.GET.get("oauth_token"), "")
consumer = OAuthConsumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
oauth_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_REQUEST_ACCESS_TOKEN_URL,
parameters={}, http_method="GET", token=token)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, token)
try:
res = urllib.urlopen(TWITTER_REQUEST_ACCESS_TOKEN_URL, oauth_request.to_postdata())
accessToken = OAuthToken.from_string(res.read())
# verify the access token
verify_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_VERIFY_CREDENTIALS,
http_method="GET", token=accessToken)
verify_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, accessToken)
res = urllib.urlopen(verify_request.to_url())
json_response = simplejson.loads(res.read())
if json_response['screen_name']:
return accessToken
request.user.message_set.create(
message=ugettext(u"Twitter authorization failed.")
)
except IOError:
request.user.message_set.create(
message=ugettext(u"Twitter authorization failed.")
)