无法更新订户信息Aweber API PHP

时间:2015-11-09 23:16:56

标签: php api aweber

我正在尝试更新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();
    }
}

3 个答案:

答案 0 :(得分:1)

您提交的自定义字段必须已存在于您的列表中,然后才能通过API提交。这可以使用此过程在您的网络控制面板中完成: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();

答案 1 :(得分: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
            );

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

请注意,即使stackoverflow现在正确地高亮显示变量名称。 而且为了Pete的缘故,让自定义字段的名称更短:)绝对是你可以制作的帖子有一个限制。拥有如此长的变量名称会使每个帖子的变量值空间更小。

哦,删除

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

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

$params = array('email' => $email, 'status' => 'subscribed');

Service.prototype = {
    get: function (params) {
        if (params[this.n]) {
            return Promise.resolve("Service " + this.n);
        }

        return Promise.reject("Service " + this.n);
    }
}

答案 2 :(得分:0)

您提交的自定义字段必须已存在于您的列表中,然后才能通过API提交。这可以使用此过程在您的网络控制面板中完成: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();