Last active
August 29, 2015 14:05
-
-
Save JacobHsu/052f57793148ed04d2d0 to your computer and use it in GitHub Desktop.
#google drive :Basic Picker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var clientId = '720409271749-hqv3lb4u0q82t68vperem5oi3kosskol.apps.googleusercontent.com'; | |
var developerKey = 'AIzaSyBTEWsJ4aXdoOzB4ey81eX9-ja7HejL4Qc'; | |
var accessToken; | |
function onApiLoad() { | |
gapi.load('auth', authenticateWithGoogle); | |
gapi.load('picker'); | |
} | |
function authenticateWithGoogle() { | |
window.gapi.auth.authorize({ | |
'client_id': clientId, | |
'scope': ['https://www.googleapis.com/auth/drive'] | |
}, handleAuthentication); | |
} | |
function handleAuthentication(result) { | |
if(result && !result.error) { | |
accessToken = result.access_token; | |
setupPicker(); | |
} | |
} | |
function setupPicker(){ | |
var picker = new google.picker.PickerBuilder() | |
.addView(new google.picker.DocsUploadView()) | |
.addView(new google.picker.DocsView()) | |
.setOAuthToken(accessToken) | |
.setDeveloperKey(developerKey) | |
.build(); | |
picker.setVisible(true); | |
} | |
</script> | |
<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment