Reputation: 91
I am building out the google picker for a project I am working on. However, the script below is what I have written for utilizing the Google Picker API, to open the picker in the page to allow users to drop items into the drive. I am trying to understand what is missing in the code functions that prevent the window from appearing.
Should I include this into a button to activate it?
<script>
function onApiload() {
gapi.load('auth', {'callback': onAuthApiLoad});
gapi.load('picker');
}
function onAuthApiLoad(){
window.gapi.auth.authorize({
'client_id': '596875534635.apps.googleusercontent.com',
'scope': ['https://www.googleapis.com/auth/drive']
}, handleAuthResult);
}
var oauthToken;
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
oauthToken = authReults.access_token;
createPicker();
}
}
function createPicker() {
var picker = new google.picker.PickerBuilder()
.addView(new google.picker.DocsUploadView())
.addView(new google.picker.DocsView())
.setAuthToken
.setDeveloperKey('AIzaSyBTsUe7i_eezFJ3ndIT8axJCR6IpksyLs8')
.build();
picker.setVisible(true);
}
</script>
<script src="https://apis.google.com/js/api.js?onload-onApiLoad">
</script>
Upvotes: 1
Views: 1117
Reputation: 116
You need to pass in the oauthToken variable to the setOAuthToken function call in your createPicker() function. Everything else looks fine (presuming that you are using the right credentials). So your createPicker() function should look like this:
function createPicker() {
var picker = new google.picker.PickerBuilder()
.addView( new google.picker.DocsUploadView() )
.addView( new google.picker.DocsView() )
.setOAuthToken( oauthToken )
.setDeveloperKey( 'AIzaSyBTsUe7i_eezFJ3ndIT8axJCR6IpksyLs8' )
.build();
// Render the picker model
picker.setVisible( true );
}
Upvotes: 2