将订阅者添加到mailchimp API v3 [英] Add subscrber to mailchimp API v3

查看:125
本文介绍了将订阅者添加到mailchimp API v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这个函数:

public function mailchimp() {

$email = 'testing123@test.com';
$first_name = 'Test';
$last_name = 'Test';

$api_key = 'dfrgergredgdfgdfgdfgdfg-us9'; // YOUR API KEY

// server name followed by a dot. 
// We use us13 because us13 is present in API KEY
$server = 'us9.'; 

$list_id = '718943'; // YOUR LIST ID

$auth = base64_encode( 'user:'.$api_key );

$data = array(
    'apikey'        => $api_key,
    'email_address' => $email,
    'status'        => 'subscribed',
    'merge_fields'  => array(
        'FNAME' => $first_name,
        'LNAME'    => $last_name
        )    
    );
$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members/');
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);
curl_setopt($ch, CURLOPT_POST, true);    
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);

$result = curl_exec($ch);

$result_obj = json_decode($result);

// printing the result obtained    
echo $result_obj->status;
echo '<br>';
echo '<pre>'; print_r($result_obj); echo '</pre>';

    }

但是我得到了这个结果(404错误),我不知道该怎么办以及哪里出了问题:

but I got this result (404 error) and I dont know what to do and where I'm wrong:

404
stdClass Object
(
    [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
    [title] => Resource Not Found
    [status] => 404
    [detail] => The requested resource could not be found.
    [instance] => 637c9154-9999-48d2-952f-e994b737a9b7
)

这是什么问题?为什么会出现404错误?我在任何地方的代码中都看不到错误.我该如何解决这个问题?

What is the problem here? Why I get 404 error? I don't see the error in my code anywhere. How I can solve this issue?

我使用Laravel 5.1 对不起,我的英语!

I use Laravel 5.1 Sorry for my English!

推荐答案

它似乎与您的列表ID有关.我不确定您是否已在问题中替换了真实的列表ID,但其格式应类似于z1593c999e而不是数字.该API所需的列表ID与在MailChimp中查看列表时在URL中看到的ID不同.

It looks like it's related to your list ID. I'm not sure if you've replaced your real list ID in the question, but its format should look something like z1593c999e rather than only numbers. The list ID required for the API is different from the one you'd see in the URL when viewing your list in MailChimp.

要找到此文件,您可以按照以下步骤操作来自MailChimp的知识库:

To find this, you can follow these steps from MailChimp's knowledgebase:

  1. 导航到列表"页面.
  2. 单击要使用的列表旁边的下拉菜单,然后选择设置".
  3. 滚动查找唯一的列表ID字段.字母和数字的字符串是列表ID.
  1. Navigate to the Lists page.
  2. Click the drop-down menu next to the list you want to work with, and choose Settings.
  3. Scroll to find the unique List ID field. The string of letters and numbers is the list ID.

您还可以使用GET方法将API请求发送到https://usX.api.mailchimp.com/3.0/lists并在响应中找到列表ID.

You can also send an API request using the GET method to https://usX.api.mailchimp.com/3.0/lists and find the list ID in the response.

这篇关于将订阅者添加到mailchimp API v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆