作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想向mailchimp列表上的特定用户添加标签
$email = "toto@example.com";
$tag="test";
$userid = md5( strtolower( $email ) );
$data = array(
'apikey' => $mailchimp_api_key,
'email_address' => $email,
'tags' => array(
'name' => $tag,
'status' => 'active'
)
);
$json_data = json_encode($data);
$url = 'https://'.$mailchimp_datacenter.'api.mailchimp.com/3.0/lists/'.$mailchimp_list_id.'/members/' . $userid . '/tags';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
if ($displaytaglist!="") {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
stdClass Object
(
[type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
[title] => Invalid Resource
[status] => 400
[detail] => Expected argument of type "array or Traversable and ArrayAccess", "string" given
[instance] => XXXXX-XXXXX-XXXXX
)
最佳答案
我必须使用嵌套数组才能使标签起作用:
$data = array(
'tags' => array(
array(
'name' => $tagname,
'status' => 'active'
)
)
);
$tagname1 = "TAG_NAME_1";
$tagname2 = "TAG_NAME_2"
$data = array(
'tags' => array(
array(
'name' => $tagname1,
'status' => 'active'
),
array(
'name' => $tagname2,
'status' => 'active'
)
)
);
$tagname1 = "TAG_NAME_1";
$tagname2 = "TAG_NAME_2";
{"tags":[{"name":"TAG_NAME_1","status":"active"},{"name":"TAG_NAME_2","status":"active"}]}
关于php - 如何在Mailchimp上的列表成员中添加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54752379/
我是一名优秀的程序员,十分优秀!