ปัญหา Mailchimp Google ชีตด้วยคีย์ api

ตัวแปรทั้งหมดส่งคืนค่าที่ถูกต้อง แต่การตอบสนอง 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 loop ไม่ได้รับการดำเนินการด้วยซ้ำเนื่องจากฉันได้รับข้อผิดพลาดต่อไปนี้สำหรับระบบอัตโนมัติข้อมูล:

TypeError: ไม่สามารถอ่านคุณสมบัติ "ข้อมูล" จากไม่ได้กำหนด (บรรทัดที่ 82 ไฟล์ "รหัส")

apiResponse ไม่ทำงาน ความช่วยเหลือใด ๆ ก็ได้รับการชื่นชม


person AspiringCanadian    schedule 26.05.2016    source แหล่งที่มา


คำตอบ (2)


ปัญหาอยู่ที่วิธีตั้งค่าโปรเจ็กต์ใน Developers Console ลองทำตามขั้นตอนอีกครั้งที่นี่ เพื่อให้คุณตรวจสอบได้ว่าคุณได้ทำไปแล้วหรือไม่ ในทางที่ถูกต้อง

คุณสามารถตรวจสอบวิธีแก้ปัญหาได้ที่นี่ในคำถาม SO นี้ เขา/เธออธิบายไว้ที่นี่ เหตุใดเขา/เธอจึงได้รับข้อผิดพลาด 401 และ 403 แบบเดียวกับที่คุณได้รับ

person KENdi    schedule 27.05.2016

ปรากฎว่าฉันใช้ v3.0 สำหรับ Mailchimp api ในขณะที่ฉันจำเป็นต้องใช้ 2.0

person AspiringCanadian    schedule 27.05.2016