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
评论列表
文章目录