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
<?php
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_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, count($postData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    
    $output=curl_exec($ch); 
    curl_close($ch);    
    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'];
}

require_once('aweber_api/aweber_api.php');
$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';
        $data['oauth_callback']=$callbackUrl;
        $data['display']='page';
        $data['oauth_token']=$requestToken;
        $result = httpPost($aweber->getAuthorizeUrl(), $data);
        $oauth_verifier=getOauthVerifier($result);
        header("Location: ".$callbackUrl."?"."oauth_token=".$requestToken."&oauth_verifier=".$oauth_verifier); 
        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();
}

$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>AWeber Application</title>
<style>
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;
}
</style>
<body>
<?php    
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>
      <tr>
        <th class="stat">Subject</th>
        <th class="value">Sent</th>
        <th class="value">Stats</th>
      </tr>";
      
    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>
                          <li><b>Opened:</b>".$campaign->total_opens."</li>
                          <li><b>Sent:</b>".$campaign->total_sent."</li>
                          <li><b>Clicked:</b>".$campaign->total_clicks."</li>
                        </ul>
                 </td></tr>";    
        }
    }  
    echo "</table>";
}
/* End Account list */
?>
</body>
</html>

About v.shakya

I am V.Shakya, Freelance PHP Programmer. 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 Ten 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.

Please fill in the form and submit to subscribe

Welcome to VShakya

For this week my all price is very low !

Don't miss to get my services

Thanks

 

Contact us