-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.html
50 lines (44 loc) · 1.44 KB
/
auth.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
46
47
48
49
50
<!doctype html>
<html>
<head>
<script src="https://www.dropbox.com/static/api/dropbox-datastores-1.0-latest.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<center>
<button id="writeButton">Click to create <code>hello.txt</code> in Dropbox.</button>
</center>
<script>
// ※デベロッパーサイトで入手したAPP KEY
var client = new Dropbox.Client({ key: '<Dropbox APP Key>' });
// AOuth認証を実行
client.authenticate({ interactive: false }, function (error) {
if (error) {
alert('Error: ' + error);
} else {
console.log("authorized successfully");
}
});
// Dropboxにファイル書き込み
function doWriteFile() {
client.writeFile('hello.txt', 'Hello, World!', function (error) {
if (error) {
alert('Error: ' + error);
} else {
alert('File written successfully!');
}
});
}
// ボタンが押された時の処理
document.getElementById('writeButton').onclick = function () {
client.authenticate(function (error, client) {
if (error) {
alert('Error: ' + error);
} else {
doWriteFile();
}
});
}
</script>
</body>
</html>