Не удается обновить информацию о подписчике Aweber API переполнение стека

Я пытаюсь обновить информацию подписчика Aweber, в частности настраиваемые поля, и я использую API Aweber, но он не работает, и, вероятно, я не правильно пишу код:

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();
}
}

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();
1

Другие решения

Я предполагаю, что вместо того, чтобы писать значения, вы пишете в виде текста $ 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 правильно подсвечивает имена переменных.
И ради Пита, сделайте имена пользовательских полей короче 🙂 Скорее всего, существует ограничение на количество сообщений, которые вы можете создавать. Наличие такого длинного имени переменной сокращает пространство в значении переменной на пост.

Ох и удали

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

И изменить из

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

в

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

или

$params = array('email' => $email, 'status' => 'subscribed');
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();
0