2015-11-09 31 views
1

我試圖更新Aweber訂戶信息,特別是自定義字段,我使用Aweber API,但它不工作,可能我沒有正確編寫代碼:無法更新訂戶信息Aweber API PHP

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

回答

0

我想,而不是寫的價值,你正在寫$ 3fears,$ 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 
      ); 

注意,即使現​​在計算器正確hightlighting變量名。 而對於皮特來說,請將自定義字段的名稱縮短一點:)當然,您可以對帖子進行限制。具有如此長的變量名稱可以減少每個帖子中變量值的空間。

哦,刪除

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

和修改

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

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

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

您提交的自定義字段必須已經存在於您的列表中,然後才能通過API提交它們。 https://help.aweber.com/hc/en-us/articles/204027516-How-Do-I-Create-Custom-Fields-

所以,如果你創建了一個名爲「年齡」,那麼您的代碼會是這個樣子(假設現有的$用戶對象)的自定義字段:

$fields = array(
    'age' => '21', 
); 
$subscriber->custom_fields = $fields; 
$subscriber->save(); 
這可以在aweber控制面板中使用此過程中完成

$subscriber['custom_fields']['age'] = '21'; 
$subscriber->save();