我目前正在尝试使用脚本编辑器将订阅者列表中预定义的自动更新细分中的订阅者总数的mailchimp数据提取到Google表格中。但是,我必须承认我在这方面不是很了解,并尝试了各种方法来自定义此代码而没有运气。我已经看过关于这个的Mailchimps文档,但似乎仍然无法完成这项工作。
function chimpSubscribers() {
var API_KEY = ''; // MailChimp API Key
var LIST_ID = ''; // MailChimp List ID
var SEGMENT_ID =''; //Mailchimp Segment ID
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Subscribers");
var dc = API_KEY.split('-')[1];
var api = 'https://'+ dc +'.api.mailchimp.com/3.0';
var memberList = '/lists/'+LIST_ID
var memberSegment = '/segments/'+SEGMENT_ID
var apiCall = function(endpoint){
options = {"headers": {"authorization": 'apikey '+API_KEY}};
apiResponseMembers = UrlFetchApp.fetch(api+endpoint,options);
json = JSON.parse(apiResponseMembers);
return json
}
var members = apiCall ("memberList", "memberSegment");
if (members) {
var d = new Date();
var member_count = members.stats.member_count;
var unsubscribe_count = members.stats.unsubscribe_count;
var open_rate = members.stats.open_rate;
var click_rate = members.stats.click_rate;
var report = [d, member_count, unsubscribe_count, open_rate, click_rate,];
Logger.log(report);
// Clear MailChimp data in Spreadsheet
sheet.clear();
// Append MailChimp data to Spreadsheet
sheet.appendRow(["Date", "Total Subscribers", "Unsubscribe Count", "Open Rate", "Click Rate"]);
sheet.appendRow(report);
}
}
答案 0 :(得分:0)
想出来 - 对于任何可能需要它的人来说,代码如下:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="bt1" type="button" value="Test call (Connection Not tested)" /> <br/> <br/>
<input id="bt2" type="button" value="Function call (Connection tested) " />