/** * API instance. * * @since 141004 * @package s2Member\List_Servers * * @return AWeberAPI|null AWeber API instance. */ public static function aw_api() { if (!$GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_api_key']) { return NULL; } // Not possible. if (!class_exists('AWeberAPI')) { // Include the AWeber API class here. include_once dirname(dirname(__FILE__)) . '/externals/aweber/aweber_api.php'; } if (count($key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_api_key'])) < 5) { return NULL; } // It's an invalid API key; i.e., authorization code. list($consumerKey, $consumerSecret, $requestToken, $tokenSecret, $verifier) = $key_parts; $internal_api_key_checksum = md5($consumerKey . $consumerSecret . $requestToken . $tokenSecret . $verifier); if (count($internal_key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'])) >= 5) { list(, , , , $checksum) = $internal_key_parts; } // Only need checksum for now. if (empty($checksum) || $checksum !== $internal_api_key_checksum) { try { $aw_api = new AWeberAPI($consumerKey, $consumerSecret); $aw_api->user->requestToken = $requestToken; $aw_api->user->tokenSecret = $tokenSecret; $aw_api->user->verifier = $verifier; if (!is_array($accessToken = $aw_api->getAccessToken()) || count($accessToken) < 2) { return NULL; } // Not possible. list($accessTokenKey, $accessTokenSecret) = $accessToken; if (!$accessTokenKey || !$accessTokenSecret) { return NULL; } // Not possible. $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'] = $internal_api_key = $consumerKey . '|' . $consumerSecret . '|' . $accessTokenKey . '|' . $accessTokenSecret . '|' . $internal_api_key_checksum; c_ws_plugin__s2member_menu_pages::update_all_options(array('ws_plugin__s2member_aweber_internal_api_key' => $internal_api_key), TRUE, FALSE, FALSE, FALSE, FALSE); } catch (Exception $exception) { return NULL; // API initialization failure. } } if (count($internal_key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'])) < 5) { return NULL; } // It's an invalid internal API key. Cannot continue. list($consumerKey, $consumerSecret, $accessTokenKey, $accessTokenSecret, $checksum) = $internal_key_parts; try { $aw_api = new AWeberAPI($consumerKey, $consumerSecret); $aw_api->___account = $aw_api->getAccount($accessTokenKey, $accessTokenSecret); return $aw_api; // AWeberAPI instance. } catch (Exception $exception) { return NULL; // API initialization failure. } }
/** * Creates access tokens */ function renew_access_tokens() { $key = $this->auth_key; $auth = $this->parse_authkey($key); $api = new AWeberAPI($auth['api_key'], $auth['api_secret']); $api->adapter->debug = $this->debug; $api->user->tokenSecret = $auth['token_secret']; $api->user->requestToken = $auth['request_token']; $api->user->verifier = $auth['auth_verifier']; try { $access_tokens = $api->getAccessToken(); return $access_tokens; } catch (Exception $e) { return false; } }
$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; } $aweber->adapter->debug = true; $account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']); $account->loadFromUrl('/accounts/326084?ws.op=getWebForms'); ?> <!DOCTYPE html> <html lang="en"> <head> <title>AWeber Test Application</title> <link type="text/css" rel="stylesheet" href="styles.css" /> <body>