如何在自定义Google表格功能中使用高级Google服务?

时间:2019-12-06 18:21:48

标签: google-apps-script google-analytics-api

我正在尝试创建一个custom Google Sheets function,该数据从Analytics Reporting V4 API中提取数据。当我从App Scripts控制台运行此功能时,它成功返回了数据。当我从电子表格中运行该函数时,出现以下错误:

API call to analyticsreporting.reports.batchGet failed with error: Request is missing required 
authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication 
credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. (line 59).

这是我在App Scripts IDE中定义的函数(再次,当我从此处按下运行按钮时,此功能正常工作):

enter image description here

这是我产生错误的电子表格的实现:

enter image description here

enter image description here

是否有一种无需使用OAuth凭证即可完成此工作的方法?据我了解,使用高级Google服务的好处是可以避免这种身份验证流程,我想利用它。

1 个答案:

答案 0 :(得分:3)

在文档中:

If your custom function throws the error message You do not have permission to call X service., the service requires user authorization and thus cannot be used in a custom function. To use a service other than those listed above, create a custom menu that runs an Apps Script function instead of writing a custom function. A function that is triggered from a menu will ask the user for authorization if necessary and can consequently use all Apps Script services.

Using Apps Script Services