1

我正在尝试更新 Aweber 订阅者信息,特别是自定义字段,并且我正在使用 Aweber API,但它不起作用,可能我没有正确编写代码:

require_once('../AweberAPI/aweber_api/aweber_api.php');
include("../config.php");

$email=$_POST["email"];
$threefears=$_POST["3fears"];
$handlefears=$_POST["handlefears"];
$threeactions=$_POST["3actions"];
$changelife=$_POST["changelife"];

$consumerKey    = '';
$consumerSecret = '';
$accessKey      = '***'; # put your credentials here
$accessSecret   = '***'; # put your credentials here
$account_id     = ''; # put the Account ID here
$list_id        = ''; # put the List ID here

$aweber = new AWeberAPI($consumerKey, $consumerSecret);


try {
    $custom_field->name = 'Favorite Color';
    $custom_field->save();  



    $params = array('email' => '$email');
    $found_subscribers = $account->findSubscribers($params);
    foreach($found_subscribers as $subscriber) {
        $subscriber->custom_fields = array(
                'Top 3 biggest fears related to dating' => '$threefears',
                'How would the person you most admire handle these fears' => '$handlefears',
                'What are 3 actions you can take today to act more like the person you most admire' => '$threeactions',
                'How will taking these actions change your attitude towards dating and your life' => '$changelife',
            );
        $subscriber->save();
    }
}
4

3 回答 3

1

您提交的自定义字段必须已经存在于您的列表中,然后您才能通过 API 提交它们。这可以使用以下过程在您的 aweber 控制面板中完成:https ://help.aweber.com/hc/en-us/articles/204027516-How-Do-I-Create-Custom-Fields-

因此,如果您创建了一个名为“age”的自定义字段,那么您的代码将如下所示(假设现有 $subscriber 对象):

$fields = array(
    'age' => '21',
);
$subscriber->custom_fields = $fields;
$subscriber->save();

或者

$subscriber['custom_fields']['age'] = '21';
$subscriber->save();
于 2016-06-20T20:14:30.913 回答
0

您提交的自定义字段必须已经存在于您的列表中,然后才能通过 API 提交,这是正确的。这可以使用以下过程在您的 aweber 控制面板中完成:https ://help.aweber.com/hc/en-us/articles/204027516-How-Do-I-Create-Custom-Fields-

创建一个名为 'age' 的自定义字段后,php 代码将是这样的

$fields = array(
'age' => '21',
);
$subscriber->custom_fields = $fields;
$subscriber->save();
于 2018-01-19T06:13:27.977 回答
0

我猜你不是写值,而是写 $threefears、$handlefears 等作为文本。

在您的示例中,您将变量作为'$variable' 而不仅仅是$variable。那将写变量名而不是变量内容。

所以,而不是

 $subscriber->custom_fields = array(
            'Top 3 biggest fears related to dating' => '$threefears',
            'How would the person you most admire handle these fears' => '$handlefears',
            'What are 3 actions you can take today to act more like the person you most admire' => '$threeactions',
            'How will taking these actions change your attitude towards dating and your life' => '$changelife',
        );

尝试

$subscriber->custom_fields = array(
                'Top 3 biggest fears related to dating' => $threefears,
                'How would the person you most admire handle these fears' => $handlefears,
                'What are 3 actions you can take today to act more like the person you most admire' => $threeactions,
                'How will taking these actions change your attitude towards dating and your life' => $changelife
            );

请注意,即使是 stackoverflow 现在也可以正确突出显示变量名称。为了 Pete 的缘故,让自定义字段的名称更短 :) 可以肯定的是,您可以发布的帖子是有限制的。拥有如此长的变量名可以减少每个帖子的变量值空间。

哦,删除

$custom_field->name = 'Favorite Color';
$custom_field->save();  

并修改自

$params = array('email' => '$email');

$params = array('email' => $email);

或者

$params = array('email' => $email, 'status' => 'subscribed');
于 2015-12-08T22:07:07.090 回答