javascript - Google picker api not entering the onApiLoad function -



javascript - Google picker api not entering the onApiLoad function -

i want integrate google drive picker api in application. onload function google picker api not calling. below code of mine.

<!doctype html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>googledriveapi</title> <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onapiload"></script> </head> <body> <div> </div> <script type="text/javascript"> /**************************************************************** start of google api code ************************************************************************************************/ // api developer key obtained google developers console. var developerkey = 'aizasyazjlxjshv3fpklk6517tiz2nywt6rjzhk'; // client id obtained google developers console. var clientid = '814476538527-pijtu7ck89ofep1j4tqr2j38ltruahtd.apps.googleusercontent.com'; // scope utilize access user's photos. var scope = ['https://www.googleapis.com/auth/drive']; var pickerapiloaded = false; var oauthtoken; // utilize api loader script load google.picker , gapi.auth. function onapiload() { console.log("load function calledd"); gapi.load('auth', { 'callback': onauthapiload }); gapi.load('picker', { 'callback': onpickerapiload }); } function onauthapiload() { console.log("auth api success"); window.gapi.auth.authorize( { 'client_id': clientid, 'scope': scope, 'immediate': false }, handleauthresult); } function onpickerapiload() { console.log("picker load"); pickerapiloaded = true; createpicker(); } function handleauthresult(authresult) { console.log("authressult"); console.log(authresult); if (authresult && !authresult.error) { oauthtoken = authresult.access_token; createpicker(); } } // create , render picker object picking user photos. function createpicker() { console.log("create picker"); if (pickerapiloaded && oauthtoken) { var picker = new google.picker.pickerbuilder(). addview(google.picker.docsuploadview()). setoauthtoken(oauthtoken). setdeveloperkey(developerkey). setcallback(pickercallback). build(); picker.setvisible(true); } } // simple callback implementation. function pickercallback(data) { var url = 'nothing'; if (data[google.picker.response.action] == google.picker.action.picked) { var doc = data[google.picker.response.documents][0]; url = doc[google.picker.document.url]; } var message = 'you picked: ' + url; document.getelementbyid('result').innerhtml = message; } /**************************************************************** end of google api code ************************************************************************************************/ </script>

the above .cshtml page called when clicking on button in page

$("#button").click(function(){ window.location.href = "/contact/googleapi"; });

controller code

public actionresult googleapi(){ retunr view("googleapi"); }

the googleapi.cshmtl page loading not calling in on onapiload function. have set googlepickerapi on. can know what's wrong in this.

using script:

script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onapiload">

in body instead of head worked me. don't know exact reason though. may have figured out since post around 6 months old. if how these scripts executed please allow me know ! executed mean order of execution !

javascript google-api google-drive-sdk google-picker

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -