简体   繁体   English

使用Mailchimp API v3添加到兴趣组

[英]Add to interest group using Mailchimp API v3

I'm using this MailChimp api v3 wrapper https://github.com/drewm/mailchimp-api/tree/api-v3 我正在使用这个MailChimp api v3包装器https://github.com/drewm/mailchimp-api/tree/api-v3

Using the example I can add an email to my list but cannot add it to one of my interest groups. 使用该示例,我可以向我的列表添加电子邮件,但无法将其添加到我的某个兴趣组。

This is the example code: 这是示例代码:

$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');
    $result = $MailChimp->post('lists/b1234346/members', array(
                'email_address'     => 'davy@example.com',
                'status'            => 'subscribed',
                'merge_fields'      => array('FNAME'=>'Davy', 'LNAME'=>'Jones'),
                'interests'         => array( '2s3a384h' => true )
                )); 
print_r($result);

My understanding is the key in that array entry for interests is the ID of the group. 我理解的关键是,兴趣的数组条目是组的ID。 I created a group in MailChimp, which has a group title and group names. 我在MailChimp中创建了一个组,其中包含组标题和组名。 I can see an id when I hover over the group title edit button, and also the group name edit button. 当我将鼠标悬停在组标题编辑按钮上时,我可以看到一个ID,还有组名称编辑按钮。 If I hover over the "0 subscribers" for a group name I can see that same id and a group_id. 如果我将鼠标悬停在“0订阅者”上以获取组名,我可以看到相同的id和group_id。 I've tried both values and I get this error: 我已经尝试了两个值,我得到这个错误:

Array ( [type] => http://kb.mailchimp.com/api/error-docs/400-invalid-resource [title] => Invalid Resource [status] => 400 [detail] => Invalid interest ID: '39561'. [instance] => 12c1ab46-a0b5-4014-8107-08cfa97a9a94 ) 数组([type] => http://kb.mailchimp.com/api/error-docs/400-invalid-resource [title] =>无效资源[状态] => 400 [详细] =>无效的兴趣ID: '39561'。[instance] => 12c1ab46-a0b5-4014-8107-08cfa97a9a94)

I've googled and still can't find the answer. 我用谷歌搜索,仍然找不到答案。 Any help? 有帮助吗?

You can get the Id of the specific interest option not the group id, by going to the playground 您可以通过去游乐场获取特定interest option的ID而不是组ID

Then you navigate to your list and group: 然后导航到您的列表和组:

导航到操场上的列表和分组

When you click on the name of the interest option it will show the option meta data, including it's id: 当您单击兴趣选项的名称时,它将显示选项元数据,包括它的ID:

在此输入图像描述

Interests are (can be? must be?) grouped under interest-categories, but you only need the ID of the interest itself, not the ID of the interest-category when setting it for the user. 兴趣是(可以是?必须?)分组在兴趣类别下,但您只需要感兴趣的ID本身,而不是为用户设置兴趣类别的ID。

Your error may be from using the interest-category ID instead of the specific interest ID. 您的错误可能来自使用兴趣类别ID而不是特定兴趣ID。

A quick and dirty way to capture all of the Interest IDs... 快速而肮脏的方式来捕获所有兴趣ID ...

$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');
    $result = $MailChimp->post('lists/b1234346/members', array(
                'email_address'     => 'davy@example.com',
                'status'            => 'subscribed',
                'merge_fields'      => array('FNAME'=>'Davy', 'LNAME'=>'Jones')
                )); 
print_r($result);

Your print_r after not specifying the "interests" key in the post should provide you with an interests array with the IDs telling you they are all marked as false. 你没有在帖子中指定“兴趣”键后你的print_r应该为你提供一个兴趣数组,其中的ID会告诉你它们都被标记为false。

["interests"]=> array(7) { ["258ad948a1"]=> bool(false) ["8e30162ec8"]=> bool(false) ["f2f79df229"]=> bool(false) ["b4e2f6effc"]=> bool(false) ["4fb0927fef"]=> bool(false) ["f2d1e06470"]=> bool(false) ["9f6c7c4db2"]=> bool(false) }

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

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