类型错误:在 Google App Script 中的对象中找不到函数 forEach

只是

在尝试循环条目时,我一直运行到无法找到每个对象错误的函数有什么我没有看到的吗?这里是代码。此代码应该通过 API 从系统中获取时间数据进行计算并发送电子邮件

function getTime() {
    var range = [5323, 9626, 4998];
    var user = [];
    for (var i = 0; i < range.length; i++) {

        var auth = 'token'

        var from = '2020-01-08'
        var to = '2020-01-09'
        var url = 'https://api.10000ft.com/api/v1/users/' + range[i] + '/time_entries?from=' + from + '&to=' + to + '&auth=' + auth;

        var options = {
            method: 'get',
            headers: {
                Authorization: 'Bearer ' + auth
            }
        };

        var submitted_time_entries = {};
        var response = UrlFetchApp.fetch(url, options);
        var response = JSON.parse(response.getContentText());
        var time_entries = response.data;

        time_entries.forEach(function (time_entry) {
            if (time_entry.user_id in submitted_time_entries) {
                submitted_time_entries[time_entry.user_id] += time_entry.hours;
            } else {
                submitted_time_entries[time_entry.user_id] = time_entry.hours;
            }
        });

        submitted_time_entries.forEach(function (user_id) {
            if (submitted_time_entries[user_id] < 3) {
                //send mail
            }
        });
    }
}
只是

似乎我的 API 返回了一个对象。我通过使用Object.keys方法找到了解决方法并且它起作用了。这是工作代码。

function getTime() {
    var range = [53, 926, 8098];
    var user = [];
    for (var i = 0; i < range.length; i++) {

        var auth = 'token';

        var from = '2020-01-08'
        var to = '2020-01-09'
        var url = 'https://api.10000ft.com/api/v1/users/' + '449625' + '/time_entries?from=' + from + '&to=' + to + '&auth=' + auth;

        var options = {
            method: 'get',
            headers: {
                Authorization: 'Bearer ' + auth
            }
        };

        var submitted_time_entries = {};
        var response = UrlFetchApp.fetch(url, options);
        var response = JSON.parse(response.getContentText());
        var time_entries = response.data;


        Object.keys(time_entries).forEach(function (time_entry) {
            if (time_entry.user_id in submitted_time_entries) {
                submitted_time_entries[time_entry.user_id] += time_entry.hours;
            } else {
                submitted_time_entries[time_entry.user_id] = time_entry.hours;
            }
        });

        Object.keys(submitted_time_entries).forEach(function (user_id) {
            if (submitted_time_entries[user_id] < 3) {
                Logger.log(time_entry)
                //send mail
            }
        });
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型错误:在对象中找不到包含函数(Google App Script)

如何使“setValue”在 Google Sheets App Script 的 foreach 中工作

如何使用Google App脚本重命名由Google云端硬盘托管的de pdf文件(在对象错误中找不到函数setName)

在R doParallel'foreach'中找不到函数-{中的错误:任务1失败-“找不到函数” raster“”

类型错误:在对象中找不到函数 getDataRange

在 google docs 文件错误中找不到函数

如何正确处理 Google App Script 中的 Google SDK 错误

Google App Script 中事件对象变量的 For 循环

如何从 GuestStatus 对象中获取 Enum 类型的值 - Google Script

类型错误:snapshot.forEach 不是函数

类型错误:msgs.forEach 不是函数

类型错误:在对象范围中找不到函数设置值

函数中的do.call-找不到对象错误

函数内eval中的“找不到对象错误”

“找不到对象'mtcars1'”:olsrr函数中的错误

GSA错误:找不到包含在对象中的函数

Google App Engine错误:NeedIndexError:找不到匹配的索引

Google-app-script 错误无效分配左侧

在PrivateObject中找不到类型的构造函数错误

在 Laravel 中找不到错误类“App\Product”

Google App Script 中的全局变量问题

验证 Google App Script 中的特定字符串

Google App Script - 如何隐藏多个工作表中的列?

如何使用 Google App Script 从 html 表单中获取数据

在 Google App Script 中獲取鍵/值對的值

使用 Google App Script 在 XML 中插入静态节点

处理 Google Apps Script Web App 中的历史更改

使用 Google App Script 从 XML 中检索文本

根据 Google App Script 中的条件禁用按钮