2015-03-31 119 views
1

我可以直接通过URL访问这个脚本,它可以正常工作,但作为cron作业不起作用。它是伟大的还是我做错了什么?Aweber不允许cron作业

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) 
 
\t { 
 
\t \t ##Add aweber 
 
\t \t require_once('aweber/aweber_api/aweber_api.php'); 
 
\t \t $consumerKey = '***'; 
 
\t \t $consumerSecret = '***'; 
 
\t \t $accessKey  = '***'; # put your credentials here 
 
\t \t $accessSecret = '***'; # put your credentials here 
 
\t \t $account_id  = '***'; # put the Account ID here 
 
\t \t $list_id  = '***'; # put the List ID here 3823593 
 
\t \t $aweber = new AWeberAPI($consumerKey, $consumerSecret); 
 
\t \t # Get an access token 
 
\t \t if(empty($_COOKIE['accessToken'])) 
 
\t \t  { 
 
\t \t   if (empty($_GET['oauth_token'])) 
 
\t \t    { 
 
\t \t     $callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
 
\t \t     list($requestToken, $requestTokenSecret) = $aweber->getRequestToken($callbackUrl); 
 
\t \t     setcookie('requestTokenSecret', $requestTokenSecret); 
 
\t \t     setcookie('callbackUrl', $callbackUrl); 
 
\t \t     header("Location: {$aweber->getAuthorizeUrl()}"); 
 
\t \t     exit(); 
 
\t \t    } 
 
\t \t   $aweber->user->tokenSecret = $_COOKIE['requestTokenSecret']; 
 
\t \t   $aweber->user->requestToken = $_GET['oauth_token']; 
 
\t \t   $aweber->user->verifier = $_GET['oauth_verifier']; 
 
\t \t   list($accessToken, $accessTokenSecret) = $aweber->getAccessToken(); 
 
\t \t   setcookie('accessToken', $accessToken); 
 
\t \t   setcookie('accessTokenSecret', $accessTokenSecret); 
 
\t \t   header('Location: '.$_COOKIE['callbackUrl']); 
 
\t \t   exit(); 
 
\t \t \t } 
 
\t \t ##End add aweber 
 

 
\t \t foreach($result as $val=>$row) 
 
\t \t \t { 
 
\t \t \t \t # Get AWeber Account 
 
\t \t \t \t \t try { 
 
\t \t \t \t \t   $account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']); 
 
\t \t \t \t \t   $listURL = "https://api.aweber.com/1.0/accounts/***/lists/".$list_id; 
 
\t \t \t \t \t   $list = $account->loadFromUrl($listURL); 
 
\t \t \t \t \t \t \t $params = array(
 
\t \t \t \t \t    'email' => $row->email 
 
\t \t \t \t \t  ); 
 
\t \t \t \t \t   $subscribers = $list->subscribers; 
 
\t \t \t \t \t   $new_subscriber = $subscribers->create($params); 
 
\t \t \t \t \t \t \t $update_data = array('aweber' => 1); 
 
\t \t \t \t \t \t \t $where = array('member_id' => $row->member_id); 
 
\t \t \t \t \t \t \t $wpdb->update('wp_members_tbl', $update_data, $where, $format = null, $where_format = null); 
 
\t \t \t \t \t   
 
\t \t \t \t \t   \t \t \t \t \t   # success! 
 
\t \t \t \t \t   //print "A new subscriber was added to the $list->name list!"; 
 
\t \t \t \t \t  } 
 
\t \t \t \t \t catch(AWeberAPIException $exc) 
 
\t \t \t \t \t  { 
 
\t \t \t \t \t   print "<h3>AWeberAPIException:</h3>"; 
 
\t \t \t \t \t   print " <li> Type: $exc->type    <br>"; 
 
\t \t \t \t \t   print " <li> Msg : $exc->message   <br>"; 
 
\t \t \t \t \t   print " <li> Docs: $exc->documentation_url <br>"; 
 
\t \t \t \t \t   print "<hr>"; 
 
\t \t \t \t \t   //exit(1); 
 
\t \t \t \t \t  } 
 
\t \t \t } 
 
\t }

回答

0

看起来像少数地方,这可能是失败的:

1)您的包括相对路径。 cron可能无法找到包含的文件。尝试将这些更改为完整路径。 2)您的代码需要浏览器环境(设置cookie,http标头位置等)。这些都不会在浏览器之外工作。

作为cron运行的用户,您应该始终从命令行执行该文件以对其进行测试。任何错误都会很明显。

要解决您的问题,您应该使用本教程使用浏览器来设置凭据。 在cron命令使用该http://engineering.aweber.com/quick-start-api-script-in-php/

0

搜索:

wget -qO- http://yoururlhere/ &> /dev/null 

这不是因为“自我要求”最好的解决方法是不推荐的,但之后,它可以在命令行中/ cron的运行它会阻止你处理环境设置。