0

所有变量都返回正确的值,但 urlfetch 响应返回 403 或 401(访问被拒绝)。

在此处输入图像描述

第一个日志输出:

 var payload = {
    "apikey": API_KEY,
    "filters": {
        "sendtime_start": REPORT_START_DATE,
        "sendtime_end": REPORT_END_DATE
    }
};
Logger.log(payload );

第二个日志输出:

var params = {
    "method": "POST", //what MC specifies
    "muteHttpExceptions": true,
    "payload": payload,
    "limit": 100
};
Logger.log(params);

第三个日志输出:

var apiCall = function(endpoint) {

    //issue with syntax here?

    var apiResponse = UrlFetchApp.fetch(automationsList, params);
    var json = JSON.parse(apiResponse);
    Logger.log(apiResponse);
    return json;
};

不工作的自动化 API 调用:

var automations = apiCall(automationsList);
var automationsData = automations.data;

for (var i = 0; i < automationsData.length; i++) {


    // are these response parameters? are these specific values getting pulled from MC - these are the type of values i want?
    var a = automationsData[i];
    var aid = a.id; // identifies unique campaign *** does this have anything to do with the call function above - it used to be as cid b/c this was for campaigns before??
    var emails_sent = a.emails_sent;
    var recipients = a.recipients;
    var report_summary = a.report_summary;
    var settings = a.settings;

    if (send_time) {

        var r = apiCall(reports, cid); // why does this have cid? but the other one didn't??
        var emails_sent = r.emails_sent;
        var opens = r.opens;
        var unique_opens = r.unique_opens;
        var clicks = r.clicks;
        var unique_clicks = r.unique_clicks;
        var open_rate = (unique_opens / emails_sent).toFixed(4);
        var click_rate = (unique_clicks / emails_sent).toFixed(4);

    }

for 循环甚至没有被执行,因为我得到了自动化数据的以下错误:

TypeError:无法从未定义中读取属性“数据”。(第 82 行,文件“代码”)

那里的 apiResponse 不知何故不起作用,感谢您的帮助。

4

2 回答 2

1

问题在于您如何在 Developers Console 中设置项目。尝试再次按照此处的流程进行操作,以验证您是否已经以正确的方式进行操作。

您还可以在此SO question中查看解决方案,他/她在此处进行了解释,为什么他/她会遇到与您相同的 401 和 403 错误。

于 2016-05-27T08:00:47.170 回答
0

事实证明,我使用 v3.0 作为 Mailchimp api,而我需要使用 2.0。

于 2016-05-27T19:22:26.093 回答