目录
申请 OpenAPI
通过后,你将得到 ClientId 和 ClientSecret
OpenAPI 调用
接口文档: https://api.cnblogs.com/Help
请求示例:Client_Credentials授权
import requests
import json
from urllib import parse
ClientId = 'xxxx'
ClientSecret = 'xxxx'
url = 'https://api.cnblogs.com/token'
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8" }
param = {
'client_id' : ClientId,
'client_secret' : ClientSecret,
'grant_type' : 'client_credentials',
}
data = parse.urlencode(param)
ret = requests.post(url=url, headers=headers, data=data)
print(ret, ret.text)
你将得到:
{
"access_token":"xxxxx",
"expires_in":10800,
"token_type":"Bearer",
"scope":"CnBlogsApi"
}
标签:cnblogs,Python,博客园,ret,OpenAPI,ClientId,https,import From: https://www.cnblogs.com/fldev/p/17929594.html