简体   繁体   English

在Mailchimp中使用API​​创建广告系列时,如何获取广告系列的网络ID?

[英]How can i get campaign's web id when campaign is created using API in Mailchimp?

I am using API version 1.3 of mailchimp to create Campaign programmatically in PHP. 我使用mailchimp的API版本1.3在PHP中以编程方式创建Campaign。

I am using MCAPI class method campaignCreate() to create campaign. 我正在使用MCAPI类方法campaignCreate()创建广告系列。 Campaign is created successfully and it returns campaign id in response which is string. 广告系列创建成功,并返回响应的广告系列ID(字符串)。

But i need Web id (integer value of campaign id) so that I can use it to open that campaign using link on my website. 但是我需要Web ID(广告系列ID的整数值),以便我可以使用它通过我网站上的链接打开该广告系列。

For example: lets say I want to redirect user to this link - https://us8.admin.mailchimp.com/campaigns/show?id=941117 and for that i need id value as 941117 when new campaign is created.For now i am getting it as string like 6ae9ikag when new campaign is created using mailchimp API 例如:可以说,我想用户重定向到这个链接- https://us8.admin.mailchimp.com/campaigns/show?id=941117和我需要的值id为941117时的新广告系列created.For现在使用mailchimp API创建新的广告系列时,我得到的字符串类似于6ae9ikag

Please let me know if anyone knows how to get campaign web id (integer value) using Mailchimp API in PHP 请让我知道是否有人知道如何使用PHP中的Mailchimp API获取广告系列的Web ID(整数值)

Thanks 谢谢

I found an answer so wanted to share here.Hope it helps someone 我找到了一个答案,所以想在这里分享。希望它可以帮助某人

I get campaign id as a string when createCampaign() method of MCAPI class is used. 使用MCAPI类的createCampaign()方法时,我以字符串形式获得广告系列ID。

You need to use below code to get web id (integer value of campaign id) 您需要使用以下代码获取网络ID(广告系列ID的整数值)

$filters['campaign_id'] = $campaign_id;  // string value of campaign id
$campaign = $api->campaigns($filters);
$web_id = $campaign['data'][0]['web_id'];

This worked for me. 这对我有用。

Thanks 谢谢

<?php
/**
This Example shows how to create a basic campaign via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MCAPI($apikey);

$type = 'regular';

$opts['list_id'] = '5ceacbda08';
$opts['subject'] = 'Test Newsletter Mail';
$opts['from_email'] = 'guna@test.com'; 
$opts['from_name'] = 'guna';

$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);

$opts['authenticate'] = true;
$opts['analytics'] = array('google'=>'my_google_analytics_key');
$opts['title'] = 'Test Newsletter Title';

$content = array('html'=>'Hello html content message', 
    'text' => 'text text text *|UNSUB|*'
  );

$retval = $api->campaignCreate($type, $opts, $content);


if ($api->errorCode){
 echo "Unable to Create New Campaign!";
 echo "\n\tCode=".$api->errorCode;
 echo "\n\tMsg=".$api->errorMessage."\n";
} else {
 echo "New Campaign ID:".$retval."\n";
}

$retval = $api->campaignSendNow($retval);

?>

The web_id is returned by mailchimp when a call is made to the creation end point. 调用创建端点时,mailchimp将返回web_id。

$mcResponce = $mailchimp_api->campaigns->create(...);
$web_id = $mcResponce['web_id'];

See the documentation . 请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM