Pytho实现百度AI平台签名,获取access_token
作者:互联网
在对接百度ai平台的接口中,需要获取access_token,所以需要根据应用的APIKey、SecretKey访问百度的签名接口进行签名,通过返回的内容获取access_token值;
百度ai平台地址:https://ai.baidu.com/
需要在代码中将,APIKey替换成你的应用的APIKey值,SecretKey替换成你SecretKey值
import requests
client_id = 'APIKey'
client_secret = 'SecretKey'
api = 'https://aip.baidubce.com/oauth/2.0/token?'
url = api + "grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret
r = requests.get(url)
data = (r.json())
access_token = data["access_token"]
print(access_token)
执行结果:
24.d7bcc7684a1234b50989397a254s916d.9867000.2987282092.220985-23661180
标签:SecretKey,APIKey,Pytho,AI,access,ai,token,client 来源: https://blog.csdn.net/weixin_43775400/article/details/119268295