本文整理汇总了Python中oauth.OAuthRequest类的典型用法代码示例。如果您正苦于以下问题:Python OAuthRequest类的具体用法?Python OAuthRequest怎么用?Python OAuthRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuthRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_api_request
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: execute
def execute(self, url, params, consumer, access_token, method='POST', mode='header'):
headers = {}
headers.setdefault('User-Agent', "python")
headers.setdefault("Accept", "text/html")
headers.setdefault("Content-Type", "application/x-www-form-urlencoded")
request = OAuthRequest.from_consumer_and_token(
self.consumer,
http_url=url,
http_method=method,
token=access_token,
parameters=params,
)
request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, access_token)
if mode == 'header':
headers.update(request.to_header())
else:
url = request.get_normalized_http_url()
params = request.to_postdata()
multipart_encode({})
host, path = _url_spllit(url)
conn = httplib.HTTPConnection(host)
conn.request(method, path, params, headers)
resp = conn.getresponse()
json = resp.read()
conn.close()
return json
示例3: start_fetch_request_token
def start_fetch_request_token(self):
oauth_request = OAuthRequest.from_consumer_and_token(
self.consumer, http_url="%s/api/auth/request_token" % self.server_url
)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, None)
webbrowser.open(oauth_request.to_url())
示例4: load
def load(self, url, method="GET", parameters=None, raw=False):
oauth_request = OAuthRequest.from_consumer_and_token(self.consumer,
token=self.access_token, http_url=url, http_method=method,
parameters=parameters)
oauth_request.sign_request(self.signature_method, self.consumer,
self.access_token)
return self.oauth_fetch(oauth_request, raw)
示例5: createOauthRequest
def createOauthRequest(http_url, params, default_params):
validateOptions(params, default_params)
default_params.update(params)
params = default_params
http_method = "GET"
token = params.pop("token", None)
base_url = "https://www.pesapal.com/api/"
if testing:
base_url = "https://demo.pesapal.com/api/"
url = base_url + http_url
if not consumer_key:
raise MissingKeyError("provide consumer key")
if not consumer_secret:
raise MissingKeyError("provide consumer consumer_secret")
oauth_consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
request = OAuthRequest.from_consumer_and_token(
oauth_consumer, http_url=url, http_method=http_method, parameters=params
)
request.sign_request(SIGNATURE_METHOD, oauth_consumer, token)
return request.to_url()
示例6: access_resource
def access_resource(self,
relative_url,
access_token,
method="GET",
params=None):
full_url = self.server_url + relative_url
url = urlparse.urlparse(full_url)
full_params = cgi.parse_qs(url.query)
for key in full_params:
full_params[key] = full_params[key][0]
if params:
full_params.update(params)
oauth_request = OAuthRequest.from_consumer_and_token(
self.consumer,
token = access_token,
http_url = full_url,
parameters = full_params,
http_method=method
)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, access_token)
if method == "GET":
response = get_response(oauth_request.to_url())
else:
response = post_response(full_url, oauth_request.to_postdata())
return response
示例7: build
def build(http_url, token, http_method='GET'):
# build and return oauth request url
match = re.match('(.+):(.+)@(.+)', token)
try:
token = oauth.OAuthToken(
match.group(1),
match.group(2)
)
except Exception:
raise InvalidAccessToken('the provided access token is invalid.')
url = BASE_API_URI + http_url
if not consumer_key:
raise MissingKeyError('provide consumer key')
if not consumer_secret:
raise MissingKeyError('provide consumer consumer_secret')
oauth_consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
request = OAuthRequest.from_consumer_and_token(
oauth_consumer,
http_url=url,
token=token,
http_method=http_method,
parameters={}
)
request.sign_request(SIGNATURE_METHOD, oauth_consumer, token)
return request.to_url()
示例8: build_oauth_request
def build_oauth_request(self, http_url, token=None,
http_method="GET", parameters=None):
oauth_request = OAuthRequest.from_consumer_and_token(
self.consumer, token=token, http_method=http_method,
http_url=http_url, parameters=parameters
)
oauth_request.sign_request(self.signature_method, self.consumer, token)
return oauth_request
示例9: exchange_request_token_for_access_token
def exchange_request_token_for_access_token(self, token):
oauth_request = OAuthRequest.from_consumer_and_token(self.consumer,
token=token, http_url=URL_OAUTH_ACCESS_TOKEN)
oauth_request.sign_request(self.signature_method, self.consumer,
token)
resp = self.oauth_fetch(oauth_request, raw=True)
self.access_token = OAuthToken.from_string(resp)
return self.access_token
示例10: login
def login():
oauth_request = OAuthRequest.from_consumer_and_token(
consumer,
callback='http://127.0.0.1:5000/oauth_callback',
http_url='http://www.khanacademy.org/api/auth/request_token'
)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
return redirect(oauth_request.to_url())
示例11: get_auth_url
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()
示例12: get
def get(self, path, token=None, prefix="/api"):
url = "http://%s%s%s" % (self.host, prefix, path)
request = OAuthRequest.from_consumer_and_token(
self.consumer,
token,
http_method='GET',
http_url=url
)
return self._send_request(request, token)
示例13: start_fetch_request_token
def start_fetch_request_token(self, callback=None):
oauth_request = OAuthRequest.from_consumer_and_token(
self.consumer,
callback=callback,
http_url="%s/api/auth/request_token" % self.server_url
)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, None)
return oauth_request.to_url()
示例14: post
def post(self, path, post_params, token=None, prefix="/api"):
url = "http://%s%s%s" % (self.host, prefix, path)
request = OAuthRequest.from_consumer_and_token(
self.consumer,
token,
http_method='POST',
http_url=url,
parameters=post_params
)
return self._send_request(request, token)
示例15: start_fetch_request_token
def start_fetch_request_token(self, callback=None):
oauth_request = OAuthRequest.from_consumer_and_token(
self.consumer,
callback=callback,
http_url="%s/api/auth/request_token" % self.server_url
)
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, None)
print 'opening webbrowser with', oauth_request.to_url()
webbrowser.open(oauth_request.to_url())