Tuesday , March 5 2024
Home / General / How to fetch aweber account subscriber list details from aweber through aweber API?

How to fetch aweber account subscriber list details from aweber through aweber API?

Below are the complete code to fetch the aweber account subscriber list details through aweber API

Download AWeber API PHP Library

Select Code
function httpPost($url,$params)
  $postData = '';
   //create name value pairs seperated by &
   foreach($params as $k => $v)
      $postData .= $k . '='.$v.'&';
   rtrim($postData, '&');
    $ch = curl_init();  
    curl_setopt($ch,CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, count($postData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    
    return $output;

function getOauthVerifier($result){
    preg_match('/<a href="(.+)">/', $result, $match); 
    $info = parse_url($match[1]);
    foreach (explode('&', str_replace('amp;','',$info['query'])) as $couple) {
        list ($key, $val) = explode('=', $couple);
        $arr[$key] = $val;
    return $arr['oauth_verifier'];

$consumerKey    = 'xxxxxxxxxxxxxxxxxxxxxxxx'; # put your credentials here
$consumerSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; # put your credentials here
$aweber = new AWeberAPI($consumerKey, $consumerSecret);

$aweber->adapter->debug = false;
# set this to true to view the actual api request and response

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);     
        $data['oauth_username']='xxxxxxxxxx';# put your aweber login username here
        $data['oauth_password']='xxxxxxxx';# # put your aweber login password here
        $data['oauth_submit']='Allow Access';
        $result = httpPost($aweber->getAuthorizeUrl(), $data);
        header("Location: ".$callbackUrl."?"."oauth_token=".$requestToken."&oauth_verifier=".$oauth_verifier); 

    $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']);

$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);
<!DOCTYPE html>
<html lang="en">
<title>AWeber Application</title>
table {
    width: 100%;
td {
    border: 1px solid #ccc;
    min-width: 50px;
    overflow: auto;
h1 {
    font-size: 16px;
    color: #f10;
h2 {
    font-size: 14px;
    color: #f10;
echo "<hr>";
/* Start to fetch account list */
foreach($account->lists as $offset => $list) {
    echo "<h1>List: ".$list->name."</h1>"; 
    echo "<h3>".$list->id."</h3>"; 
    echo "<table>
        <th class="stat">Subject</th>
        <th class="value">Sent</th>
        <th class="value">Stats</th>
    foreach($list->campaigns as $campaign) {
        if ($campaign->type == 'broadcast_campaign') {    
            echo "<tr>
                    <td class='stat'><em>".$campaign->subject."</em></td>
                    <td class='value'>".date('F j, Y h:iA',  strtotime($campaign->sent_at))."</td>
                    <td class='value'><ul>
    echo "</table>";
/* End Account list */

About v.shakya

I am V.Shakya, Software Developer & Consultant I like to share my ideas, views and knowledge to all of you who come across my website. I am young, enthusiastic, highly motivated and self disciplined person. I completed my studies in Master of Computer Application and currently giving my technical expertise to one of the Big IT company. I have more than fifteen years of experience in vast field of Programming , Designing and Development of websites and various software's.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.