Mailchimp api 3.0错误:“Schema描述对象,找到数组”是代码还是在mailchimp的结尾?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mailchimp api 3.0错误:“Schema描述对象,找到数组”是代码还是在mailchimp的结尾?相关的知识,希望对你有一定的参考价值。
我需要使用mailchimp的api和我的数据库中的订阅者列表批量更新我的mailchimp列表中的订阅者。
我正在尝试在这里实现问题的解决方案:Mailchimp API 3.0 Batch Subscribe 但我收到了错误
{“type”:“http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/”,“title”:“资源无效”,“状态”:400,“详细信息”:“无法验证提交的资源。有关特定于字段的详细信息,请参阅'errors'数组。 “,”instance“:”8198a6e9-9a7c-4e00-8365-3a7062f047f3“,”errors“:[{”field“:”“,”message“:”架构描述对象,找到的数组代替“}]}
我见过有类似问题的人,有时候在mailchimp结束时出现了问题,有时这是数据传递的问题。任何洞察我是否需要修复代码或联系mailchimp将不胜感激!
有问题的脚本:
<?php
$apikey = 'myapi'; // Your Mailchimp ApiKey
$list_id = 'mylist'; // your List ID Where you want to add subscriber
$servername = 'myserver';
$username = 'myun';
$password = 'mypw';
$dbname = 'mydb';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
$sql = 'SELECT * FROM emails Limit 2';
$result = $conn->query($sql);
$finalData = array();
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
$individulData = array(
'apikey' => $apikey,
'email_address' => $row['email'],
'status' => $row['status'],//subscribe,pending,unsubscribe
'merge_fields' => array(
'FNAME' => $row['FNAME'],
'LNAME' => $row['LNAME'],
'BARCODE' => $row['BARCODE'],
'SERVICE' => $row['SERVICE'],
'PURCHASE' => $row['PURCHASE'],
)
);
$json_individulData = json_encode($individulData);
$finalData['operations'][] =
array(
"method" => "PUT",
"path" => "/lists/$list_id/members/",
"body" => $json_individulData
);
}
}
$api_response = batchSubscribe($finalData, $apikey);
print_r($api_response);
$conn->close();
/**
* Mailchimp API- List Batch Subscribe added function
*
* @param array $data Passed you data as an array format.
* @param string $apikey your mailchimp api key.
*
* @return mixed
*/
function batchSubscribe(array $data, $apikey)
{
$auth = base64_encode('user:' . $apikey);
$json_postData = json_encode($data);
$ch = curl_init();
$dataCenter = substr($apikey, strpos($apikey, '-') + 1);
$curlopt_url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/batches/';
curl_setopt($ch, CURLOPT_URL, $curlopt_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic ' . $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.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_postData);
$result = curl_exec($ch);
return $result;
}
?>
我有类似的问题,消息是“Schema描述字符串,而是找到布尔值”。似乎json_encode()有特殊字符的问题
我用这个代码解决了它,也许它适用于你:utf8_encode($ row ['FNAME'])或你可以尝试使用(字符串)。我希望这可以帮助某人。我使用POST而不是PUT示例:
$stringData = array(
'apikey' => $api_key,
'email_address' => $row['email'],
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => utf8_encode($row['FNAME']),
'LNAME' => utf8_encode($row['LNAME'])
)
);
以上是关于Mailchimp api 3.0错误:“Schema描述对象,找到数组”是代码还是在mailchimp的结尾?的主要内容,如果未能解决你的问题,请参考以下文章
Mailchimp api 3.0错误:“Schema描述对象,找到数组”是代码还是在mailchimp的结尾?
Mailchimp api 3.0 错误:“架构描述了对象,而是找到了数组”是代码还是在 mailchimp 的末尾?
使用 RestSharp 向 Mailchimp API 3.0 查询帐户详细信息时出现“API 密钥丢失”错误
为啥在连接到 mailchimp API 3.0 时出现 401 错误