Cannot call Google Script API Functions from Web App (TypeError: Cannot read property 'run' of undefined)

邮差的信 提交于 2019-11-29 07:26:18

You need to load the Google File Picker using the Google API Loader library.

Replace:

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

with:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>google.load("picker", "1", {callback:function(){pickerApiLoaded =!0}});</script>

Remember to publish a new version of the web app after making this change.

Update: Erik from the Google Apps Script team says " the cause of the problem is that when the Picker API loads into google.picker, it is currently overwriting google.script, so google.script.run() calls start failing."

They have posted an alternate solution - manually preserve and restore google.script when loading the Picker API:

window.script = google.script;
gapi.load('picker', '1', {callback: function() {
  google.script = window.script;
  // ...
}});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!