2016-05-26 62 views
0

所有變量都返回正確的值,但urlfetch響應返回403或401(拒絕訪問)。Mailchimp Google表問題與api鍵

enter image description here

第一個日誌輸出:

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調用,是不是WO rking:

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循環甚至沒有得到執行,因爲我得到了automationsData以下錯誤:

TypeError: Cannot read property "data" from undefined. (line 82, file "Code")

的apiResponse有莫名其妙不能正常工作,任何幫助表示讚賞。

回答

0

事實證明,我使用v3.0作爲Mailchimp api,而我需要使用2.0。

1

問題在於如何在Developers Console中設置項目。嘗試再次按照here的流程進行操作,以確認您是否已經以正確的方式執行此操作。

您也可以查看SO question這裏的解決方案,他/她在這裏解釋它,爲什麼他/她得到相同的401和403錯誤。