赞
踩
百度智能云管理中心网址:https://console.bce.baidu.com/
def get_baidu_token() -> str:
"""获得百度的token"""
import requests
ak = "jSr......" # 第2步中的API Key
sk = "Qef....." # 第2步中的Secret Key
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={0}&client_secret={1}'.format(
ak, sk)
response = requests.get(host)
if response:
# print(response.json()) # 这是返回的字段
# print('token:', response.json()['refresh_token'])
# print('有效期:', response.json()['expires_in'])
return response.json()['access_token']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。