首页 > 解决方案 > 使用 Zenloop 的 API 和 Apps 脚本将数据从 Zenloop 拉入 Google 表格

问题描述

我正在尝试使用 Apps Script 将 Zenloop(调查工具)中的调查数据自动提取到 Google 表格中。执行该函数时,会出现以下错误:

错误:

异常:返回代码 401 的请求失败https://api.zenloop.com。截断的服务器响应:{"error":{"code":"UNAUTHORIZED","status":401,"title":"Invalid or expired token."}}(使用 muteHttpExceptions 选项检查完整响应)

脚本:

    function myFunction() {
      const options = {
      method: 'GET',
      headers: {
        Authorization: 'XXXXXXXXXXX',
        'Content-Type': 'application/json'
      }
    };
    
    UrlFetchApp.fetch('https://api.zenloop.com/v1/survey_groups/XXXXXXXXXXX/answers?date_shortcut=all_time&order_type=desc&page=1', options)
      .then(response => response.json())
      .then(response => console.log(response))
      .catch(err => console.error(err));
    }

我已经删除了 API 密钥和调查 ID。我是 Apps Script/Javascript 的新手,所以这里的任何人都会非常感激。API 密钥或调查 ID 没有问题,我已经检查了三次。

标签: javascriptgoogle-apps-scriptgoogle-oauthhttprequesturlfetch

解决方案


推荐阅读