forked from MrSwitch/hello.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_upload.html
59 lines (46 loc) · 1.37 KB
/
google_upload.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
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<link rel="stylesheet" href="/adorn/adorn.css"/>
<script src="/adorn/adorn.js" async></script>
<script src="client_ids.js"></script>
<script>
// DEBUGGING
window.addEventListener('message', function(){
console.debug(arguments[0].origin, arguments[0].data);
});
</script>
<h1>hello.js to Google Drive</h1>
<form onsubmit="return upload('google');">
<input type="file" id="file"/> <button type="submit">Upload to Google root</button>
</form>
<pre class="response"></pre>
<p>Include the SDK's</p>
<script src="../src/hello.js" class="pre"></script>
<script src="../src/modules/google.js" class="pre"></script>
<p>Add event listeners for the login completed event and make a request for the users profile. Once that's loaded push it to the page. </p>
<script class="pre">
hello.init({
google : GOOGLE_CLIENT_ID
}, {
redirect_uri:'../redirect.html',
scope : 'publish_files'
});
</script>
<p>The function called when the above form is submitted</p>
<script class="pre">
function upload(network){
var google = hello("google");
google.login().then(function() {
google.api('me/files', 'post', {
file : document.getElementById('file')
}).then(function(response) {
log(response);
});
});
return false;
}
</script>
<script>
function log(s){
document.body.querySelector('.response').appendChild(document.createTextNode(JSON.stringify(s, true, 2)));
}
</script>