谷歌脚本编辑器 mailchimp - 获取段订阅者
Posted
技术标签:
【中文标题】谷歌脚本编辑器 mailchimp - 获取段订阅者【英文标题】:google script editor mailchimp - fetch segment subscriber 【发布时间】:2018-02-09 06:44:24 【问题描述】:我目前正在尝试使用脚本编辑器将订阅者列表中预定义的自动更新段中订阅者总数的 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);
【问题讨论】:
【参考方案1】:想通了 - 对于其他可能需要它的人,代码如下:
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 +'/segments/'+ SEGMENT_ID
options = "headers": "authorization": 'apikey '+API_KEY;
var apiCall = function(endpoint)
apiResponseMembers = UrlFetchApp.fetch(api+endpoint,options);
json = JSON.parse(apiResponseMembers);
return json
var members = apiCall(memberList);
if (members)
var d = new Date();
var member_count = members.member_count;
var report = [d,member_count,];
Logger.log(report);
// Clear MailChimp data in Spreadsheet
sheet.clear();
// Append MailChimp data to Spreadsheet
sheet.appendRow(["Date", "Total Subscribers"]);
sheet.appendRow(report);
【讨论】:
以上是关于谷歌脚本编辑器 mailchimp - 获取段订阅者的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Mailchimp 列表 ID API 获取取消订阅 URL
Django,使用 Mailchimp 列表发送取消订阅的电子邮件
如何使用 Gibbon gem 编辑 mailchimp 列表中现有成员的电子邮件地址