2016-05-26 2 views
0

すべての変数が正しい値を返していますが、urlfetch応答は403または401(アクセス拒否)を返します。Mailchimp apiキーを使用したGoogleシートの問題

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); 

第三のログ出力:woのではない

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呼び出し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); 

    } 

ザ・ループのためにも、私はautomationsDataための次のエラーを取得するために実行されますされていません。

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

apiResponse働いていない何とかがあり、任意のヘルプは高く評価されます。

答えて

0

Mailchimp APIにv3.0を使用していましたが、2.0を使用する必要がありました。

1

問題はDevelopers Consoleでプロジェクトを設定する方法にあります。あなたがすでに正しい方法でそれを行っているかどうかを確認するために、プロセスhereをもう一度お試しください。

SO questionで解決方法を確認することもできますが、ここで説明したように、なぜ401/403エラーが発生するのですか。

関連する問題