本文整理汇总了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)
示例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()
示例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()
示例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()]