-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get_Dropbox_token_for_Hichi-mon.html
45 lines (45 loc) · 2.1 KB
/
Get_Dropbox_token_for_Hichi-mon.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'>
<!--
* Hichi power monitor (https://github.com/DE-cr/Hichi-mon)
* using esp32 with (optional) ssd1306 display
* (file Get_Dropbox_token_for_Hichi-mon.html)
-->
<html>
<head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
</head>
<body>
<title>Get Dropbox token for Hichi-mon</title>
Use <b><a href="https://www.dropbox.com/oauth2/authorize?client_id=thxk84djxdn9ox2&token_access_type=offline&response_type=code" target="_blank">this link</a></b>
to obtain an initial access code for your Dropbox account,<br>
then insert that code into the following text field and click "submit" to receive<br>
a value that can be used for DROPBOX_REFRESH_TOKEN in Hichi-mon's config.h,<br>
so that Hichi-mon can store log files and screenshots in your Dropbox.<br>
<br>
<form>
<input type="text" id="code">
<button type="button" id="submit">submit</button>
<br> <br> <output id="msg"></output>
<br><code><output id="val"></output></code>
</form>
<script>
document.querySelector('#submit').addEventListener('click',get_code);
function get_code() {
let xhr = new XMLHttpRequest();
xhr.open('POST','https://api.dropbox.com/1/oauth2/token');
xhr.setRequestHeader('Authorization','Basic dGh4azg0ZGp4ZG45b3gyOmg5NTRoaGM2MDN4YnpyYQ==');
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.onload = () => {
if (xhr.status == 200) {
document.querySelector('#msg').textContent = 'Use this in Hichi-mon\'s config.h:';
document.querySelector('#val').textContent = '#define DROPBOX_REFRESH_TOKEN "' + JSON.parse(xhr.responseText).refresh_token + '"';
} else {
document.querySelector('#msg').textContent = 'Sorry, that didn\'t work:';
document.querySelector('#val').textContent = JSON.parse(xhr.responseText).error_description;
}
};
xhr.send('grant_type=authorization_code&code='+document.querySelector('#code').value);
}
</script>
</body>
</html>