2015-03-31 66 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的運行它會阻止你處理環境設置。