当前位置: 首页>>代码示例>>Python>>正文


Python OAuthRequest.to_url方法代码示例

本文整理汇总了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)
开发者ID:skabber,项目名称:django-twitterauth,代码行数:21,代码来源:views.py

示例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.")
        )
开发者ID:skabber,项目名称:django-twitterauth,代码行数:26,代码来源:views.py


注:本文中的oauth.oauth.OAuthRequest.to_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。