我試圖向市場發布 Google Sheets 編輯器插件。由于插件選單項未添加到表格插件選單中,因此被拒絕列出。這是我從審核團隊那里得到的圖片:
選單項正在onOpen()觸發器功能中添加,并且在開發環境中作業正常。
第一次發布被拒絕了,因為我不知道該onOpenScriptApp.AuthMode限制,并實施必要onInstall()只是為了通話onOpen()所描述的,
以下是JSON格式的“例外:您沒有權限”過濾的對應錯誤日志條目
{ "insertId": "-vw46i0f1p6gav", "jsonPayload": { "message": "例外:您無權執行該操作。\n at addMenu(src/macros:27:36)\n at onOpen( src/macros:16:3)", "context": { "reportLocation": { "lineNumber": 27, "functionName": "addMenu", "filePath": "src/macros" } }, "serviceContext": { "service": "AKfycbx5HHHMsaYBlD39Pf3UmyM0JhkFUWIpxU0Iw3Jp-XYCBw" } }, "resource": { "type": "app_script_function", "labels": { "invocation_type": "簡單觸發器", "function_name": "project_Open" ": "gothic-space-325413" } }, "timestamp": "2021-11-24T20:49:50.684Z",“嚴重性”: “ERROR”, “標簽”:{ “script.googleapis.com/deployment_id”: “AKfycbx5HHHMsaYBlD39Pf3UmyM0JhkFUWIpxU0Iw3Jp-XYCBw”, “script.googleapis.com/process_id”:“EAEA1GOytih2wJPcuJNmCqsYzsqHKmik2d0KexhRdxq9Bi-T9frqnuGYZ_0XT1d0rvTIF6w5AWR5km2z2arNDWNHrShY88Z1ZvRKKib5hX46-e1oqdrpz0T7Fxc7xNnOrWXglwuTsdOQp0CbTO-4KgutgMRotiOjwArel5QOYPKYkhD8Jb-oJ6mYPa__KPLAug- Li3IzIbR_g5y9YffLMHhY-Chd_SlfcaxuB607i30zSFjBdmtYnQreN5KXKUzfXJ60SHHNtLPZZVeaozQDB6roqP82bgzZliyU7X12Y “ ”script.googleapis.com/project_key“: ”MVmLkhkHw02MpGp6YjTYdgIJQT15o7EEE“, ”script.googleapis.com/user_key“: ”APrZfepJTnqDE2xPOOZyy7vfu7vWpovS3THrJ8F1CIHw5sc / 710lPeQ940fg7V6II4bRKBAqBvr2“}, ”LOGNAME“:” 專案/哥特式的空間,325413 /日志/script.googleapis。com/console_logs", "receiveTimestamp": "2021-11-24T20:49:51.726293367Z" }
questions:
It is right to assume
onInstall()is not running, according to cloud error and logging? If yes - what can be the reason?I thought maybe, this is something with what the review team did, or maybe did not do. For example: First time they installed the addon, so it is being added to the main menu (i.e. Formula Analyzer), but the sub items are missing because of the missing
onInstall(). Second review they just open the document again, so Formula Analyzer is still there, but theonOpenfails (again) because they did not re-install the addon. Just an assumption - I do not know of course if it is a valid scenario, or what they are actually doing..More importantly maybe, this is a scenario I was considering before, how to test-imitate market installation in dev environment, without add on is published yet. How can one test the onInstall trigger? I couldn't still find the way. This is why after the first rejection and the fix, I published for review again, without actually testing it. I tried asking the review team, if it is possible and how, but they ignore. And here we are again.
How to solve this?
uj5u.com熱心網友回復:
問題:
如果沒有為當前檔案啟用加載項并且它剛剛安裝,onOpen觸發器無權訪問該檔案。
解釋:
在檔案中首次使用加載項之前,該檔案未啟用該加載項。在這些情況下,簡單物件onOpen無權訪問該檔案,并且與該檔案相關的方法(如SpreadsheetApp.getActive()或Spreadsheet.addMenu)相應地失敗。
由于可以在不呼叫 的情況下安裝附加組件onOpen,因此當您稍后呼叫 時onOpen,它可能不會以AuthMode.FULL( 的授權模式onInstall)運行。
因此,應該設計一個附加組件,以便onOpen觸發器可以運行AuthMode.NONE(即,在為用戶安裝了附加組件但未為檔案啟用的情況下),并且審核團隊嘗試正確在沒有onInstall. 因此,不應在該函式中使用訪問當前檔案的方法。
這就是為什么在編輯器附加組件的檔案代碼片段中不使用像Spreadsheet.addMenu這樣的方法,而是使用Ui.createAddonMenu() 的原因,因為該方法不訪問檔案,因此可以在onOpen.
代碼示例:
function onOpen() {
var menu = SpreadsheetApp.getUi().createAddonMenu();
menu.addItem('Trace precedents', 'tracePrecedents');
menu.addItem('Trace dependents', 'traceDependents');
menu.addToUi();
}
筆記:
您會注意到此方法不允許您命名選單。這是因為,由于這是為附加組件設計的,因此選單名稱將與附加組件名稱相匹配。
進一步閱讀:
- 編輯器附加組件的自定義選單
- 安裝與啟用
- 授權方式
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/374849.html
標籤:google-apps-script google-cloud-platform oauth
上一篇:通過時間觸發器復制月度表
下一篇:如果我通過pipinstallpyspark安裝了pyspark,在哪里修改spark-defaults.conf
