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


Python OAuthRequest.from_token_and_callback方法代码示例

本文整理汇总了Python中oauth.OAuthRequest.from_token_and_callback方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthRequest.from_token_and_callback方法的具体用法?Python OAuthRequest.from_token_and_callback怎么用?Python OAuthRequest.from_token_and_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.OAuthRequest的用法示例。


在下文中一共展示了OAuthRequest.from_token_and_callback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_api_request

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import from_token_and_callback [as 别名]
def make_api_request(access_token, url, data=None):
    
    # break down the url, as we'll need to later
    request_type, host, port, path = _split_server_parts(url)
    
    parameters = {
        'oauth_consumer_key': settings.CODA_KEY,
        'oauth_token': access_token.key,
        'oauth_signature_method': 'HMAC-SHA1',
        'oauth_timestamp': str(int(time.time())),
        'oauth_nonce': os.urandom(10).encode('hex'),
        'oauth_version': '1.0',
        'format': 'json',
        }
        
    # data should be a dict of things
    if data:
        for k in data.keys():
            parameters[k] = data[k]
        
    newurl = '%s://%s:%d%s' % (request_type, host, port, path)
    #newurl = '%s://%s%s' % (request_type, host, port, path)
        
    oauth_request = OAuthRequest.from_token_and_callback(access_token,  
        http_method="POST",
        http_url=newurl, 
        parameters=parameters)
    signature_method = OAuthSignatureMethod_HMAC_SHA1()
    consumer = OAuthConsumer(settings.CODA_KEY, settings.CODA_SECRET)
    access_token_t = OAuthToken(access_token.key, access_token.secret)
    signature = signature_method.build_signature(oauth_request, consumer,
        access_token_t)
    
    parameters['oauth_signature'] = signature
    
    if request_type == 'http':
        conn = httplib.HTTPConnection(host, port)
    else:        
        conn = httplib.HTTPSConnection(host, port)
    conn.putrequest('POST', path)

    data = ''
    for key in parameters.keys():
        data += '%s=%s&' % (key, urllib.quote(parameters[key]))
    data = data[:-1]

    print data

    conn.putheader('content-length', str(len(data)))
    conn.endheaders()
    conn.send(data)
    conn.send('\n\r\n\r')

    resp = conn.getresponse()

    data = resp.read()
        
    print data
        
    return simplejson.loads(data)    
开发者ID:camvine,项目名称:nabaztagdemo,代码行数:62,代码来源:oauthwrapper.py

示例2: get_auth_url

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import from_token_and_callback [as 别名]
    def get_auth_url(self):
        """ """
        request = OAuthRequest.from_consumer_and_token(
            self.consumer,
            http_url = self.request_token_url,
            callback = self.callback)

        request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, None)
        resp = urllib2.urlopen(urllib2.Request( request.to_url()))
        token = resp.read()
        request_token = OAuthToken.from_string(token)
        self.request_token = request_token

        request = OAuthRequest.from_token_and_callback(
            token=request_token, http_url=self.authenticate_url,
            callback = self.callback
            )
        return request.to_url()
开发者ID:wayly,项目名称:cnapi,代码行数:20,代码来源:api.py

示例3: get_authorization_url

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import from_token_and_callback [as 别名]
 def get_authorization_url(self, request_token):
     url = API_HOME + '/oauth/authorize'     
     request =  OAuthRequest.from_token_and_callback(request_token,
                                                     http_url=url)
     return request.to_url()
开发者ID:roymax,项目名称:py-sinaly,代码行数:7,代码来源:__init__.py

示例4: make_request_token_and_authorization_url

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import from_token_and_callback [as 别名]
 def make_request_token_and_authorization_url(self, callback_url):
     response = self.get("/oauth/request_token", prefix="").read()
     token = OAuthToken.from_string(response)
     request = OAuthRequest.from_token_and_callback(token=token, callback=callback_url, http_url='http://%s/oauth/authorize' % self.authority)
     return [token, request.to_url()]
开发者ID:spulec,项目名称:buriedtv,代码行数:7,代码来源:JtvClient.py


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