lhiro
1
1. 浏览器访问
2. 点击允许之后从地址栏拿取code
var code = '请填入你的code'
var xhr = new XMLHttpRequest()
xhr.open('POST', `https://connect.linux.do/oauth2/token`, false)
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
xhr.setRequestHeader('Authorization', 'Basic aGkzZ2VKWWZUb3RvaVI1UzYydTNyaDRXNXRTZUM1VUc6Vk1QQlZvQWZPQjVvamtHWFJERXR6dkRoUkxFTkhwYU4=')
xhr.onload = function() {
if (xhr.status === 200) {
const res = JSON.parse(xhr.response)
if (res && res.access_token) {
var userXhr = new XMLHttpRequest()
userXhr.open('GET', 'https://connect.linux.do/api/user', false)
userXhr.setRequestHeader('Authorization', `Bearer ${res.access_token}`)
userXhr.onload = function() {
if (userXhr.status === 200) {
console.log(userXhr.response)
}
}
userXhr.send()
}
}
}
xhr.send(`grant_type=authorization_code&code=${code}`)
4. 然后你就看到你要的了
10 Likes