gpt4 book ai didi

java - MailChimp API java 集成

转载 作者:行者123 更新时间:2023-12-01 10:47:49 28 4
gpt4 key购买 nike

我尝试将 mailChimp API 与 java 代码集成。我指的是MailChimp api tutorial at Codenvy.com但在功能上:

public String execute() throws Exception{

ListsMethod listsMethod = new ListsMethod();
listsMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us7";
ListsResult listsResult = mailChimpClient.execute(listsMethod);
ListInformation data = listsResult.data.get(0);

CampaignCreateMethod campaignCreateMethod = new CampaignCreateMethod();
campaignCreateMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us7";
campaignCreateMethod.type = CampaignType.plaintext;
campaignCreateMethod.options = new Options(data.id, "Test Campaign", "abc@xyz.com", "Codenvy", "Codenvy Users");
campaignCreateMethod.content = new Content("This is a test campaign");
String campaignId = mailChimpClient.execute(campaignCreateMethod);

CampaignSendNowMethod campaignSendNowMethod = new CampaignSendNowMethod();
campaignSendNowMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us7";
campaignSendNowMethod.cid = campaignId;
mailChimpClient.execute(campaignSendNowMethod);

setMessage("You have successfully created a campaign and sent it to recipients.");
return "SUCCESS";
}

campaignCreateMethod.optionscampaignCreateMethod.content 出错。我该如何修复它以及如何在我的 mailchimp.com 帐户中获取所有 campaignIdReference : Wrapped MailChimp API methods

最佳答案

试试这个:

 MailChimpClient mailChimpClient = new MailChimpClient();
ListsMethod listsMethod = new ListsMethod();
listsMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
ListsResult listsResult = mailChimpClient.execute(listsMethod);
ListInformation data = listsResult.data.get(0);
System.out.println(data);
try {
CampaignCreateMethod campaignCreateMethod = new CampaignCreateMethod();

campaignCreateMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
campaignCreateMethod.type = CampaignType.regular;

MailChimpObject options = new MailChimpObject();

campaignCreateMethod.options = new MailChimpObject();
options.put("list_id", "xxxxxxxxxxc");
options.put("subject", "xxxxxxxxxxxxxxxx");
options.put("from_email", "xxxx@ssss.in");
options.put("from_name", "xxxxx");
options.put("authenticate", true);
options.put("title", "xxxxxxx");
options.put("tracking", "");
campaignCreateMethod.options = options;


String str = "<!DOCTYPE html> <html> <head> <h1 text-align = center>hi</h1> </head><body text-align=centre><a herf='https://apidocs.mailchimp.com/api/2.0/campaigns/create.php'><i>My First CSS Example</i></a><p>This is a paragraph.</p></body> </html>";

MailChimpObject content = new MailChimpObject();
content.put("html", str);
//content.put("html_HEADER", "xxxxxx");
//content.put("text", "xxxxxx..... *|UNSUB|*");
//content.put("url", "https://apidocs.mailchimp.com/api/1.3/campaigncreate.func.php");
// content.put("type_opts", "regular");
// content.put("archive", "");
//content.put("email_type_option", true);

//content.put("segment_opts", "");
//content.put("template_id", 1);
//Set values for MailChimpObject
campaignCreateMethod.content = content;
Gson gson = new Gson();
String responseString = gson.toJson(content);
System.out.println(responseString);
String campaignId = mailChimpClient.execute(campaignCreateMethod);

CampaignSendNowMethod campaignSendNowMethod = new CampaignSendNowMethod();
campaignSendNowMethod.apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
campaignSendNowMethod.cid = campaignId;
mailChimpClient.execute(campaignSendNowMethod);
} catch (Exception ex) {
System.out.println(ex);
}

关于java - MailChimp API java 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23862939/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com