【问题标题】:AWeber API: subscribers->create() not working as expected in scriptAWeber API:subscribers->create() 在脚本中没有按预期工作
【发布时间】:2012-09-17 18:31:44
【问题描述】:

AWeber API 没有明确记录的程度再怎么强调也不过分(他们的示例脚本也不能很好地工作)。编写了以下脚本,因此我可以为一个用户订阅从表单中选择的多个列表。

无论如何,当subscribers->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

【问题讨论】:

    标签: php aweber


    【解决方案1】:

    你应该有这样的:...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;
    

    【讨论】:

      猜你喜欢
      • 2022-08-16
      • 2014-05-07
      • 2012-05-10
      • 2022-12-17
      • 2019-06-16
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      相关资源
      最近更新 更多