0

我在https://labs.aweber.com/apps上创建了一个应用程序,并在他们的 github https://github.com/aweber/AWeber-API-PHP-Library 上下载了 php代码。我读过他们的文档,但不是那么清楚。我不知道如何开始或先做什么。我只是一个初学者,我以前从未做过应用程序。

我首先尝试在我的页面上创建 PHP 脚本,希望在提交表单时满足所需的功能,但什么也没发生。我联系了他们的支持,但他们建议制作一个应用程序以使其正常工作。

Web 表单提交的流程是这样的。在主页中,用户将输入其姓名、电子邮件、电话,并且有两个单选选项可供选择,当您选择一个时,它将重定向到另一个页面并再次填写表格并提交。我为主页和第二页创建了一个 Web 表单。当您在第二页提交表单时,它应该会在主页上获得详细信息(姓名、电子邮件、电话和选项选择),我得到了它的工作。但是当我在我的 Aweber 帐户上查看订阅者时,第二页中的字段都是空白的。主页上的字段是完整的,每当我填写完第二页上的表格并提交时,Aweber 说该页面已被阻止。

他们建议我为此创建一个应用程序。但我不知道如何开始,因为他们的文档令人难以置信。

如果您能帮助我,我将不胜感激。

谢谢!

4

1 回答 1

14

听起来您确实需要为该功能创建一个 aweber 应用程序。

我正在粘贴 PHP 代码,这有助于我非常快速地进行设置。将其加载到浏览器中并按照说明进行操作。一旦您准备好进行实际的 API 调用,您可以在 labs.aweber.com/snippets/subscribers 看到一些示例。

如果您遇到任何问题,您可以随时通过 api@aweber.com 向 aweber API 支持发送电子邮件。

您需要做的几件事(如果您还没有):

  1. 创建一个实验室帐户 ( http://labs.aweber.com ) 和一个 aweber 帐户 ( http://www.aweber.com )
  2. 创建一个应用程序以在实验室站点获取您的使用者密钥和秘密
  3. 从实验室站点下载 AWeber php 库,并确保在下面的 require_once() 中有正确的路径
<?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();
}
?>
于 2013-03-14T17:37:23.880 回答