我正在尝试编写 .JSON 以从我的 MailChimp 帐户中提取订阅者列表。我已按照网站上的文档进行操作并获得以下信息:
{
"name": "export/export",
"description": "MailChimp Export",
"require": {
"mailchimp/mailchimp": "dev-
master",
"apigen/apigen": "~4.1@dev"
},
"authors": [
{
"name": "Ben Loya",
"email": "bal2155@columbia.edu"
}
],
"minimum-stability": "dev"
}
$apikey = '6e1f2f874b81bbbd8a8d1dcae88353c1-us7';
$list_id = 'CUFSN Members';
$chunk_size = 4096; //in bytes
$url = 'http://us7.api.mailchimp.com/export/1.0/list?apikey='.$apikey.'&id='.$list_id;
/** a more robust client can be built using fsockopen **/
$handle = @fopen($url,'r');
if (!$handle) {
echo "failed to access url\n";
} else {
$i = 0;
$header = array();
while (!feof($handle)) {
$buffer = fgets($handle, $chunk_size);
if (trim($buffer)!=''){
$obj = json_decode($buffer);
if ($i==0){
//store the header row
$header = $obj;
} else {
//echo, write to a file, queue a job, etc.
echo $header[0].': '.$obj[0]."\n";
}
$i++;
}
}
fclose($handle);
}
当我运行 composer install
时,我得到以下信息:
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 15:
$apikey = '6e1f2f874
------------------^
Expected one of: 'EOF', '}', ',', ']'
我的语法有什么问题?我是 .JSON 格式的新手 - 请原谅任何愚蠢和/或明显的错误。
最佳答案
我建议您使用 http://jsonlint.com/检查语法。
在“mailchimp/mailchimp”之后有空格:“dev-”,那不应该在那里。
为了避免这些 json 拼写错误,您可以像这样通过 CLI 使用安装包:composer require mailchimp/mailchimp
。
关于php - 拉取列表的 MailChimp PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28491965/