2015-03-30 77 views
0

我試圖在Aweber列表中添加成員,當他們在我的網站上註冊時,但我收到一個錯誤。Aweber與PHP的集成

我想知道是否有人可以幫助我。

我得到: AWeberAPIException: 類型:NotFoundError 消息:對象:無,名: '' 文檔:https://labs.aweber.com/docs/troubleshooting#notfound

我敢肯定這是$名單= $帳戶 - > loadFromUrl($ listURL) ;下面。 你能告訴我我做錯了什麼嗎?

謝謝你們

<?php error_reporting(E_ALL); 
 
ini_set('display_errors', 1); 
 
require_once('aweber_api/aweber_api.php'); 
 
$consumerKey = '**********'; 
 
$consumerSecret = '**********'; 
 
$accessKey  = '***'; # put your credentials here 
 
$accessSecret = '***'; # put your credentials here 
 
$account_id  = '***'; # put the Account ID here 
 
$list_id  = 'awlist5252553'; # put the List ID here 
 
$aweber = new AWeberAPI($consumerKey, $consumerSecret); 
 
# Get an access token 
 
if (empty($_COOKIE['accessToken'])) 
 
    { 
 
     if (empty($_GET['oauth_token'])) 
 
      { 
 
       $callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
 
       list($requestToken, $requestTokenSecret) = $aweber->getRequestToken($callbackUrl); 
 
       setcookie('requestTokenSecret', $requestTokenSecret); 
 
       setcookie('callbackUrl', $callbackUrl); 
 
       header("Location: {$aweber->getAuthorizeUrl()}"); 
 
       exit(); 
 
      } 
 
     $aweber->user->tokenSecret = $_COOKIE['requestTokenSecret']; 
 
     $aweber->user->requestToken = $_GET['oauth_token']; 
 
     $aweber->user->verifier = $_GET['oauth_verifier']; 
 
     list($accessToken, $accessTokenSecret) = $aweber->getAccessToken(); 
 
     setcookie('accessToken', $accessToken); 
 
     setcookie('accessTokenSecret', $accessTokenSecret); 
 
     header('Location: '.$_COOKIE['callbackUrl']); 
 
     exit(); 
 
} 
 
# Get AWeber Account 
 
try { 
 
     $account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']); 
 
     $listURL = "/accounts/".$account_id."/lists/".$list_id; 
 
     $list = $account->loadFromUrl($listURL); 
 
     # create a subscriber 
 
     $params = array(
 
      'email' => $_POST['email'] 
 
     ); 
 
     $subscribers = $list->subscribers; 
 
     $new_subscriber = $subscribers->create($params); 
 
     # success! 
 
     print "A new subscriber was added to the $list->name list!"; 
 

 
    } 
 
catch(AWeberAPIException $exc) 
 
    { 
 
     print "<h3>AWeberAPIException:</h3>"; 
 
     print " <li> Type: $exc->type    <br>"; 
 
     print " <li> Msg : $exc->message   <br>"; 
 
     print " <li> Docs: $exc->documentation_url <br>"; 
 
     print "<hr>"; 
 
     exit(1); 
 
    }?>

回答

2

替換以下行

$listURL = "/accounts/".$account_id."/lists/".$list_id; 
    $list = $account->loadFromUrl($listURL); 

與以下行

$lists = $account->lists->find(array('name' => $listName)); 
$list = $lists[0]; 

$ listName這裏指的是列表的名稱,而不是列表ID

+0

謝謝..這工作。 – Popsyjunior 2016-03-16 23:38:58

+0

否@d g的答案更相關。 – 2017-12-27 11:09:08

1

$ list_id應該是數字列表ID而不是字符串列表名稱。正確的代碼應該是:

$list_id  = 5252553; # put the List ID here 
+0

非常感謝。真的他們的文件很爛。 – 2017-12-27 11:08:32