首页 > 解决方案 > Google App 脚本 - 例外:您无权调用 UrlFetchApp.fetch

问题描述

OnOpen()函数上,我运行一个自定义函数来检查用户令牌是否有效,但我从谷歌得到以下错误。

Google Apps Script: Error: Error: Exception: You do not have permission to call UrlFetchApp.fetch. Required permissions: 

我已经在网上查过了,解决办法是在appscript.json

https://www.googleapis.com/auth/script.external_request

我已经添加了,但我仍然从谷歌收到同样的错误。

这就是我的appscript.json样子

{
  "timeZone": "America/New_York",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": ["https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/script.container.ui"],
  "runtimeVersion": "V8"
}

这是我的onOpen()功能

const onOpen = () => {
  const { token } = getPresetData();
  if (token) {
    const isTokenValid = validateUserToken();  // <---- this is where I make a request to my server 
    if(isTokenValid){
      console.log('token is valid');
      getMenu(true);
    }else{
      console.log('token is not valid');
      getMenu(false)
    }
  } else {
    console.log('token is undefined');
    getMenu(false);
  }
};

错误信息

标签: javascriptgoogle-apps-scriptgoogle-sheets

解决方案


推荐阅读