How to create an app in Aweber?

2020-06-29 23:44发布

I create an app on https://labs.aweber.com/apps and download the php codes on their github https://github.com/aweber/AWeber-API-PHP-Library. Ive read their docs but its not that clearly. I dont know how to start or what to do first. Im just a beginner and I never made an app before.

I tried first creating PHP scripts on my pages hoping to meet a desired functionality when submitting a form but nothing happened. I contact their support but they suggest making an app to make it work correctly.

The flow of the web form submission was like this. In the homepage, a user would input its Name, Email, Phone and there are two radio options to choose, when you choose one, it would redirect to another page and fill out a form again and submit it. I created a web form for the homepage and also on the second page. When you submit the form on second page, it should get the details on the homepage (Name,Email,Phone and option choose) and I got it worked. But when I view it on the subscribers on my Aweber account, the fields in the second page is all blank. The fields on the homepage was complete and whenever I finish filling up the form on the second page and submit it, the Aweber says the page has been blocked.

They suggest I would create an app for that. But I don't know how to get started because their docs is mindboggling.

I would really appreciate if you could help me.

Thanks!

标签: php api aweber
1条回答
▲ chillily
2楼-- · 2020-06-30 00:14

It does sound like you need to create an aweber app for that functionality.

I'm pasting PHP code which has helped me get setup very quickly. Load it in your browser and follow the directions. Once you are ready to make actual API calls, you can see some examples at labs.aweber.com/snippets/subscribers.

If you run into any issues you can always email aweber API support at api@aweber.com.

A couple of things you need to do (if you haven't already):

  1. Create a labs account (http://labs.aweber.com) and an aweber account (http://www.aweber.com)
  2. Create an app to get your consumer key and secret at the labs site
  3. Download the AWeber php library from the labs site and make sure you have the proper path to it in the require_once() below
<?php
require_once('aweber_api/aweber_api.php');
// Step 1: assign these values from https://labs.aweber.com/apps
$consumerKey = '';
$consumerSecret = '';

// Step 2: load this PHP file in a web browser, and follow the instructions to set
// the following variables:
$accessKey = '';
$accessSecret = '';
$list_id = '';

if (!$consumerKey || !$consumerSecret){
    print "You need to assign \$consumerKey and \$consumerSecret at the top of this script and reload.<br><br>" .
        "These are listed on <a href='https://labs.aweber.com/apps' target=_blank>https://labs.aweber.com/apps</a><br>\n";
    exit;
}

$aweber = new AWeberAPI($consumerKey, $consumerSecret);
if (!$accessKey || !$accessSecret){
    display_access_tokens($aweber);
}

try { 
    $account = $aweber->getAccount($accessKey, $accessSecret);
    $account_id = $account->id;

    if (!$list_id){
        display_available_lists($account);
        exit;
    }

    print "You script is configured properly! " . 
        "You can now start to develop your API calls, see the example in this script.<br><br>" .
        "Be sure to set \$test_email if you are going to use the example<p>";

    //example: create a subscriber
    /*
    $test_email = '';
    if (!$test_email){
    print "Assign a valid email address to \$test_email and retry";
    exit;
    }
    $listURL = "/accounts/{$account_id}/lists/{$list_id}"; 
    $list = $account->loadFromUrl($listURL);
    $params = array( 
        'email' => $test_email,
        'ip_address' => '127.0.0.1',
        'ad_tracking' => 'client_lib_example', 
        'misc_notes' => 'my cool app', 
        'name' => 'John Doe' 
    ); 
    $subscribers = $list->subscribers; 
    $new_subscriber = $subscribers->create($params);
    print "{$test_email} 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); 
}

function get_self(){
    return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}

function display_available_lists($account){
    print "Please add one for the lines of PHP Code below to the top of your script for the proper list<br>" .
            "then click <a href='" . get_self() . "'>here</a> to continue<p>";

    $listURL ="/accounts/{$account->id}/lists/"; 
    $lists = $account->loadFromUrl($listURL);
    foreach($lists->data['entries'] as $list ){
        print "<pre>\$list_id = '{$list['id']}'; // list name:{$list['name']}\n</pre>";
    }
}

function display_access_tokens($aweber){
    if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])){

        $aweber->user->requestToken = $_GET['oauth_token'];
        $aweber->user->verifier = $_GET['oauth_verifier'];
        $aweber->user->tokenSecret = $_COOKIE['secret'];

        list($accessTokenKey, $accessTokenSecret) = $aweber->getAccessToken();

        print "Please add these lines of code to the top of your script:<br>" .
                "<pre>" .
                "\$accessKey = '{$accessTokenKey}';\n" . 
                "\$accessSecret = '{$accessTokenSecret}';\n" .
                "</pre>" . "<br><br>" .
                "Then click <a href='" . get_self() . "'>here</a> to continue";
        exit;
    }

    if(!isset($_SERVER['HTTP_USER_AGENT'])){
        print "This request must be made from a web browser\n";
        exit;
    }

    $callbackURL = get_self();
    list($key, $secret) = $aweber->getRequestToken($callbackURL);
    $authorizationURL = $aweber->getAuthorizeUrl();

    setcookie('secret', $secret);

    header("Location: $authorizationURL");
    exit();
}
?>
查看更多
登录 后发表回答