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


Python Client.request方法代码示例

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


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

示例1: get_access_token

# 需要导入模块: from oauthlib.oauth1 import Client [as 别名]
# 或者: from oauthlib.oauth1.Client import request [as 别名]
def get_access_token(consumer_key,
                     consumer_secret,
                     req_token_key,
                     req_token_secret,
                     verifier,
                     access_token_url,
                     validate_certs=True):
    method = 'GET'
    params = {'format': 'json', 'oauth_callback': 'oob'}
    # they're really serious about that oob
    full_url = access_token_url + "&" + urllib.urlencode(params)
    client = OAClient(consumer_key,
                      client_secret=consumer_secret,
                      resource_owner_key=req_token_key,
                      resource_owner_secret=req_token_secret,
                      verifier=verifier,
                      signature_type=SIGNATURE_TYPE_QUERY)
    full_url, headers, body = client.sign(full_url, method)

    client = httplib2.Http()
    client.disable_ssl_certificate_validation = not validate_certs
    resp, content = client.request(full_url, method=method)
    try:
        resp_dict = json.loads(content)
        acc_token_key, acc_token_secret = resp_dict['key'], resp_dict['secret']
    except:
        raise ValueError('access token step failed: %s\n\nheaders, etc.: %s'
                         % (content, pformat(resp)))
    return acc_token_key, acc_token_secret
开发者ID:hatnote,项目名称:omwcat,代码行数:31,代码来源:mwoauth.py

示例2: make_api_call

# 需要导入模块: from oauthlib.oauth1 import Client [as 别名]
# 或者: from oauthlib.oauth1.Client import request [as 别名]
def make_api_call(consumer_key,
                  consumer_secret,
                  access_token_key,
                  access_token_secret,
                  method,
                  params,
                  api_url,
                  body=None,
                  headers=None):

    headers = dict(headers or {})
    method = method.upper()
    params = dict(params, format='json')
    if method == 'GET':
        full_url = api_url + "?" + urllib.urlencode(params)
    elif method == 'POST':
        full_url = api_url
        body = urllib.urlencode(params)
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
    else:
        raise ValueError('unsupported HTTP method %r' % method)

    client = OAClient(consumer_key, client_secret=consumer_secret,
                      resource_owner_key=access_token_key,
                      resource_owner_secret=access_token_secret)
    full_url, headers, body = client.sign(full_url, method, body, headers)

    client = httplib2.Http()
    client.disable_ssl_certificate_validation = True

    resp, content = client.request(full_url,
                                   method=method,
                                   body=body,
                                   headers=headers)
    return content
开发者ID:hatnote,项目名称:omwcat,代码行数:37,代码来源:mwoauth.py


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