wordpress - 使用 Mailchimp API 从 woocommerce 中的 mailchimp 获取成员详细信息时出错
问题描述
我正在尝试将 mailchimp API API 链接与 woocommerce 集成。我正在尝试在 mailchimp 中添加用户。在将用户添加到 mailchimp 列表之前,如果用户不在 mailchimp 列表中,我会使用 getListMember 方法搜索用户,我会将用户添加到列表中但如果用户存在于列表中,我将更新状态。为了搜索用户,我创建了一个自定义函数 getMemberInfo($email) 我在将用户添加到 mailchimp 列表之前调用此函数
function getMemberInfo($email)
{
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => $GLOBALS['mailchimpAPI'],
'server' => $GLOBALS['mailchimpServer']
]);
$list_id = $GLOBALS['mailchimpListID'];
$subscriberHash = md5(strtolower($email));
try {
$response = $mailchimp->lists->getListMember($list_id, $subscriberHash);
//print_r($response);
if($response->status == 404)
{
return 0;
}else{
return 1;
}
} catch (MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
}
但我收到以下错误
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://usxx.api.mailchimp.com/3.0/lists/debxxxxxxxx/members/xxxxxxxxxd207ccxxxxxxx6a5d238` resulted in a `404 Not Found` response:
{"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Resource Not Found","status":404,"detail":"The (truncated...)
in D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace:
#0 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true)
#5 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#7 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Client.php(123): GuzzleHttp\Promise\Promise->wait()
#10 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\mailchimp\marketing\lib\Api\ListsApi.php(4218): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array)
#11 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\mailchimp\marketing\lib\Api\ListsApi.php(4207): MailchimpMarketing\Api\ListsApi->getListMemberWithHttpInfo('debxxxxxxxx', 'xxxxxxxxxd207ccxxxxxxx6a5d238...', NULL, NULL)
#12 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\mailchimp-api.php(80): MailchimpMarketing\Api\ListsApi->getListMember('debxxxxxxxx', 'xxxxxxxxxd207ccxxxxxxx6a5d238...')
#13 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\functions.php(351): getMemberInfo('test1009@test...')
#14 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(303): save_my_account_page_custom_details(33)
#15 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#16 D:\xampp\htdocs\wpreg\wp-includes\plugin.php(470): WP_Hook->do_action(Array)
#17 D:\xampp\htdocs\wpreg\wp-content\plugins\woocommerce\includes\class-wc-form-handler.php(348): do_action('woocommerce_sav...', 33)
#18 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(303): WC_Form_Handler::save_account_details('')
#19 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#20 D:\xampp\htdocs\wpreg\wp-includes\plugin.php(470): WP_Hook->do_action(Array)
#21 D:\xampp\htdocs\wpreg\wp-includes\template-loader.php(13): do_action('template_redire...')
#22 D:\xampp\htdocs\wpreg\wp-blog-header.php(19): require_once('D:\\xampp\\htdocs...')
#23 D:\xampp\htdocs\wpreg\index.php(17): require('D:\\xampp\\htdocs...')
#24 {main}
thrown in D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
更新
为了添加用户,我正在使用流动功能。这个功能工作正常
function subscribeEmailToMailChimp($email,$fname,$lname)
{
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => $GLOBALS['mailchimpAPI'],
'server' => $GLOBALS['mailchimpServer']
]);
$list_id = $GLOBALS['mailchimpListID'];
try {
$response = $mailchimp->lists->addListMember($list_id, [
"email_address" => $email,
"status" => "subscribed",
"merge_fields" => [
"FNAME" => $fname,
"LNAME" => $lname
]
]);
//print_r($response);
} catch (MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
}
任何建议
解决方案
推荐阅读
- javascript - 在所有标签中查找单词并在 jQuery 中替换它
- python - 在 Python 中使用 openCV 对矩阵执行 blob 检测
- css - 来自侧边栏关闭(X)图标的警报模式
- asp.net - 为什么我的身份验证状态提供程序不起作用?
- r - 在 R 中复制记录并为每个重复记录输入具有不同值的新列
- c++ - 如何将代码分成多个.cpp文件C++
- c# - 带有实体框架的 Blazor webassembly 失败,并显示“不支持 ContentType;支持的类型是 'application/json'”
- node.js - 在作为firebase函数运行的快速应用程序中获取完整的url——包括函数名?
- word-wrap - iText7 html 到 pdf 不能打断长词
- git - 阻止 git 跟踪临时打开的 Microsoft Office 文件