我可以通过 URL 直接访问这个脚本,它工作正常,但作为一个 cron 作业 ot 不起作用。是 aweber 还是我做错了什么?
Awebre 的文档是我遇到过的最糟糕的文档之一!
我不确定为什么他们的文档中没有对此进行解释!
谢谢
<?php
include "wp-load.php";
include_once('wp-includes/class-phpass.php');
$sql = "SELECT member_id, email FROM wp_members_tbl WHERE aweber != 1";
$result = $wpdb->get_results($sql);
if(count($result)>0)
{
##Add aweber
require_once('aweber/aweber_api/aweber_api.php');
$consumerKey = '***';
$consumerSecret = '***';
$accessKey = '***'; # put your credentials here
$accessSecret = '***'; # put your credentials here
$account_id = '***'; # put the Account ID here
$list_id = '***'; # put the List ID here 3823593
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
# Get an access token
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();
}
##End add aweber
foreach($result as $val=>$row)
{
# Get AWeber Account
try {
$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);
$listURL = "https://api.aweber.com/1.0/accounts/***/lists/".$list_id;
$list = $account->loadFromUrl($listURL);
$params = array(
'email' => $row->email
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
$update_data = array('aweber' => 1);
$where = array('member_id' => $row->member_id);
$wpdb->update( 'wp_members_tbl', $update_data, $where, $format = null, $where_format = null);
# success!
//print "A new subscriber 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);
}
}
}