orcid_api.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:orcid-demo 作者: lizkrznarich 项目源码 文件源码
def get_orcid_token():
    #set request variables
    client_id = config.orcid_client_id
    client_secret = config.orcid_client_secret
    token_endpoint = config.token_endpoint
    data = BytesIO()
    #create post data
    post_data = {'client_id': client_id, 'client_secret': client_secret, 'scope': '/read-public', 'grant_type': 'client_credentials'}
    #url encode post data
    postfields = urllib.urlencode(post_data)
    #create and send http request
    c = pycurl.Curl()
    c.setopt(c.URL, token_endpoint)
    c.setopt(c.HTTPHEADER, ['Accept: application/json'])
    c.setopt(c.POSTFIELDS, postfields)
    c.setopt(c.WRITEFUNCTION, data.write)
    c.perform()
    c.close()
    #get request response
    json_object = json.loads(data.getvalue())
    token = json_object['access_token']
    return token
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号