AWeber API 没有明确记录的程度不能被足够强调(他们的示例脚本也不能很好地工作)。编写了以下脚本,因此我可以为一个用户订阅从表单中选择的多个列表。
无论如何,当订阅者->创建方法被注释掉时,这个脚本就可以工作。我可以看到我单独的列表 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