-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.js
34 lines (30 loc) · 940 Bytes
/
code.js
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
var access_token = 'YOUR_TOKEN_HERE';
function ajax(params) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
params.success(this.responseText);
} else {
console.error(new Error('Response returned with error code.'));
console.error(this.responseText);
}
}
};
request.open(params.type, params.url, true);
params.beforeSend(request);
request.send();
}
ajax({
type: 'POST',
beforeSend: function(request) {
request.setRequestHeader('Content-Type', 'application/octet-stream');
request.setRequestHeader('Authorization', `Bearer ${access_token}`);
request.setRequestHeader('Dropbox-API-Arg', '{"import_format":"markdown"}');
},
url: 'https://api.dropboxapi.com/2/paper/docs/create',
success: function(resp) {
var data = JSON.parse(resp);
window.location = `https://paper.dropbox.com/doc/${data.doc_id}`;
},
});