This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
forked from russpos/AWeber-API-PHP-Library
-
Notifications
You must be signed in to change notification settings - Fork 22
/
demo.php
73 lines (67 loc) · 2.33 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require_once('aweber_api/aweber_api.php');
// Replace with the keys of your application
// NEVER SHARE OR DISTRIBUTE YOUR APPLICATIONS'S KEYS!
$consumerKey = "************************";
$consumerSecret = "*********************************";
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
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();
}
# set this to true to view the actual api request and response
$aweber->adapter->debug = false;
$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>AWeber Test Application</title>
<link type="text/css" rel="stylesheet" href="styles.css" />
<body>
<?php
foreach($account->lists as $offset => $list) {
?>
<h1>List: <?php echo $list->name; ?></h1>
<h3><?php echo $list->id; ?></h3>
<table>
<tr>
<th class="stat">Subject</th>
<th class="value">Sent</th>
<th class="value">Stats</th>
</tr>
<?php
foreach($list->campaigns as $campaign) {
if ($campaign->type == 'broadcast_campaign') {
?>
<tr>
<td class="stat"><em><?php echo $campaign->subject; ?></em></td>
<td class="value"><?php echo date('F j, Y h:iA', strtotime($campaign->sent_at)); ?></td>
<td class="value"><ul>
<li><b>Opened:</b> <?php echo $campaign->total_opens; ?></li>
<li><b>Sent:</b> <?php echo $campaign->total_sent; ?></li>
<li><b>Clicked:</b> <?php echo $campaign->total_clicks; ?></li>
</ul>
</td>
<?php
}
} ?>
</table>
<?php }
?>
<body>
</html>