Difference between revisions of "Web Element: Data"
Line 185: | Line 185: | ||
<html> | <html> | ||
− | + | <body> | |
− | + | <button id="authorize-button" style="visibility: hidden">Authorize</button> | |
− | + | <script type="text/javascript"> | |
− | + | ||
− | + | // NOTE: You must replace the client id on the following line. | |
− | + | var clientId = '549821307845-9ef2xotqflhcqbv10.apps.googleusercontent.com'; | |
+ | var scopes = 'https://www.googleapis.com/auth/spreadsheets'; | ||
+ | |||
+ | function init() { | ||
+ | gapi.auth.authorize( | ||
+ | {client_id: clientId, scope: scopes, immediate: true}, | ||
+ | handleAuthResult); | ||
+ | } | ||
− | + | function handleAuthResult(authResult) { | |
− | + | var authorizeButton = document.getElementById('authorize-button'); | |
− | + | if (authResult && !authResult.error) { | |
− | } | + | authorizeButton.style.visibility = 'hidden'; |
+ | makeApiCall(); | ||
+ | } else { | ||
+ | authorizeButton.style.visibility = ''; | ||
+ | authorizeButton.onclick = handleAuthClick; | ||
+ | } | ||
+ | } | ||
− | + | function handleAuthClick(event) { | |
− | + | gapi.auth.authorize( | |
− | + | {client_id: clientId, scope: scopes, immediate: false}, | |
− | + | handleAuthResult); | |
− | + | return false; | |
+ | } | ||
− | + | function makeApiCall() { | |
− | + | // Note: The below spreadsheet is "Public on the web" and will work | |
− | + | // with or without an OAuth token. For a better test, replace this | |
− | + | // URL with a private spreadsheet. | |
− | + | var tqUrl = 'https://docs.google.com/spreadsheets' + | |
− | </ | + | '/d/1XWJLkAwch5GXAt_7zOFDcg8Wm8Xv29_8PWuuW15qmAE/gviz/tq' + |
− | + | '?tqx=responseHandler:handleTqResponse' + | |
− | + | '&access_token=' + encodeURIComponent(gapi.auth.getToken().access_token); | |
+ | |||
+ | document.write('<script src="' + tqUrl +'" type="text/javascript"></script>'); | ||
+ | } | ||
+ | |||
+ | function handleTqResponse(resp) { | ||
+ | document.write(JSON.stringify(resp)); | ||
+ | } | ||
+ | |||
+ | </script> | ||
+ | <script src="https://apis.google.com/js/auth.js?onload=init"></script> | ||
</body> | </body> | ||
</html> | </html> |
https://docs.google.com/spreadsheets/d/1YUqF27YsO2tVdFL1R6Oxu5BT5itjA_ozZDrekzfFclk/edit?usp=sharing
'); } function handleTqResponse(resp) { document.write(JSON.stringify(resp)); }
hkilter.com by H. K. Ilter is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
© 2020 H. K. Ilter