AWeber API:subscriber-> create()在脚本中无法正常工作

时间:2012-09-17 18:31:44

标签: php aweber

AWeber API没有明确记录的程度无法得到足够的强调(他们的示例脚本也不能很好地工作)。编写下面的脚本,以便我可以将一个用户订阅到从表单中选择的多个列表。

无论如何,当subscriber-> create方法被注释掉时,这个脚本可以工作。我能够看到我的单独列表id提供给列表URL,然后获取并返回列表数组数据。但是一旦重新添加了create方法,它只会通过循环执行一次,将email参数订阅到它找到的第一个列表,然后脚本停止:

<!DOCTYPE html>
<html>
<body>
<?php

require_once('aweber_api/aweber_api.php');
require_once('aweber_api/aweber_creds.php');

print "----<br>";
$aweber->adapter->debug = true;
   print "----<br>";
//call the api key...
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
$account = $aweber->getAccount($accessKey, $accessSecret);

$feeds = array_values($_GET);
//print form array
print "FORM ARRAY ";
print_r ($feeds);
echo "--<br>";
foreach($feeds[1] as $feed){
    echo "--<br>";
try {
       print "<br> Feed : $feed";
       $listURL = "/accounts/{$account_id}/lists/{$feed}";
       $list = $account->loadFromUrl($listURL);
       $lists = $account->lists->find(array('name' => $listName));
       print_r ($list);
     print "<br><br><br>";
        # create a subscriber
         $params = array(
             'email' => $feeds[0],
          );
      $subscribers = $list->subscribers;
      $new_subscriber = $subscribers->create($params);
      print "HERE " . $new_subscriber->email;
      # success!
      print "$new_subscriber->email was added to the $list->name list!";

} catch(AWeberAPIException $exc) {
    print "<h3>AWeberAPIException:</h3>";
    print " <li> Type: $exc->type              <br>";
    print " <li> Msg : $exc->message           <br>";
    print " <li> Docs: $exc->documentation_url <br>";
    print "<hr>";
}
}
?>
</body>
</html>

为了上下文,这里有一些传递给这个脚本的表单参数:

somehostnamehere.com/phptest/aweber_api/hltmt_addsubsv1.php?email=user22344%40gmail.com&aweber_list%5B%5D=2531241&aweber_list%5B%5D=2531242&aweber_list%5B%5D=2531243&aweber_list%5B%5D=2531244

1 个答案:

答案 0 :(得分:0)

你应该这样:...php?email=user22344@gmail.com 所以,请使用urldecode(),例如:

 $final = 'somehostnamehere.com/phptest/aweber_api/hltmt_addsubsv1.php?'. urldecode('email=user22344%40gmail.com&aweber_list%5B%5D=2531241&aweber_list%5B%5D=2531242&aweber_list%5B%5D=2531243&aweber_list%5B%5D=2531244');
 echo $final;