前面的 https://oauth.cnblogs.com/connect/token 都走通了,获取到 access_token,走到 https://api.cnblogs.com/api/users 怎么都走不下去了。
目前报 403 错误。
太难了,写个app像闯关一样,一下午处处惊险,希望博客园加油改进啊,真的想认真写个好的应用。
建议提供一下对应的调用代码
调用 /api/users 需要在获取 token 之前调用 /connect/authorize ,参考 python 代码
chrome: WebDriver = webdriver.Chrome()
u = URLObject("https://oauth.cnblogs.com/connect/authorize").add_query_params(
client_id=CLIENT_ID,
scope="openid profile CnBlogsApi offline_access",
response_type="code id_token",
redirect_uri=REDIRECT_TARGET,
state="this is state string",
nonce=random_str(16),
response_mode="form_post"
)
print(str(u))
p_url = str(u)
chrome.get(p_url)
chrome.implicitly_wait(30)
print(chrome.title)
t = Thread(target=_check_until_finish, args=(chrome,))
t.start()
t.join()
print(chrome.current_url)
pre = chrome.find_element_by_tag_name("pre").text
data = json.loads(pre)
code = data["code"]
print("code: " + code)
chrome.close()
response = requests.post("https://oauth.cnblogs.com/connect/token", data={
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"grant_type": "authorization_code",
"code": code,
"redirect_uri": REDIRECT_TARGET
})