【问题标题】:MailChimp PHP Script to Pull ListsMailChimp PHP 脚本来拉取列表
【发布时间】:2015-04-14 01:03:49
【问题描述】:

我正在尝试编写一个 .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 格式非常陌生 - 请原谅任何愚蠢和/或明显的错误。

【问题讨论】:

    标签: php json mailchimp


    【解决方案1】:

    我建议你使用http://jsonlint.com/ 来检查语法。

    "mailchimp/mailchimp": "dev-" 后面有空格,不应该有。


    为避免这些 json 拼写错误,您可以通过 CLI 使用安装包,如下所示:composer require mailchimp/mailchimp

    【讨论】:

      猜你喜欢
      • 2013-08-18
      • 2013-06-13
      • 1970-01-01
      • 2013-07-19
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      相关资源
      最近更新 更多