Aweber与PHP集成

时间:2015-03-30 23:33:20

标签: php api aweber

我想在我的网站上注册时向Aweber列表添加成员,但是我收到了错误。

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

我得到: AWeberAPIException: 键入:NotFoundError 消息:对象:无,名称:'' 文档:https://labs.aweber.com/docs/troubleshooting#notfound

我很确定它是$ list = $ account-> 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);
    }?>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

替换以下行

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

以下行

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

$ listName这里是指列表的名称,而不是列表ID

答案 1 :(得分:1)

$ list_id应该是数字列表id而不是字符串列表名称。正确的代码应该是:

$list_id        = 5252553; # put the List ID here