Я пытаюсь обновить информацию о подписчике 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();
}
}
Пользовательские поля, которые вы отправляете, должны уже существовать в вашем списке, прежде чем вы сможете отправить их через 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();
Правильно, что пользовательские поля, которые вы отправляете, должны уже существовать в вашем списке, прежде чем вы сможете отправить их через 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();
Я предполагаю, что вместо написания значений вы пишете $ threefears, $ handlefears и т.д. Как текст.
В вашем примере вы помещаете переменные как '$ 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 - это правильные имена переменных hightlighting. И ради Пете, сделайте имена пользовательских полей короче :) Скорее всего, существует ограничение на сообщение, которое вы можете сделать. Наличие такого длинного имени переменной делает меньше места в переменной величине за сообщение.
Ох и удалите
$custom_field->name = 'Favorite Color';
$custom_field->save();
И изменить из
$params = array('email' => '$email');
в
$params = array('email' => $email);
или
$params = array('email' => $email, 'status' => 'subscribed');