Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid fatal error: Uncaught OAuthException when using cron job
    text
    copied!<p>Hi hope somone can help with this one. Ive had a birthday reminder app built, that aquires the usual permissions including offline access etc.</p> <p>The app requires a daily cron job to be run on my server. When I run the cron file a recieve the below error</p> <p>Fatal error: Uncaught OAuthException: Invalid OAuth access token signature. thrown in blah/base_facebook.php on line 1140;</p> <p>Is there a common reason for the error, am i doing anything wrong that stands out, and should i be displaying more code to get help from people?</p> <p>below are the lines leading up to the error. My code ends on line 1140;</p> <pre><code>&lt;?php $name = 'api'; if (isset($READ_ONLY_CALLS[strtolower($method)])) { $name = 'api_read'; } else if (strtolower($method) == 'video.upload') { $name = 'api_video'; } return self::getUrl($name, 'restserver.php'); } protected function getUrl($name, $path='', $params=array()) { $url = self::$DOMAIN_MAP[$name]; if ($path) { if ($path[0] === '/') { $path = substr($path, 1); } $url .= $path; } if ($params) { $url .= '?' . http_build_query($params, null, '&amp;'); } return $url; } protected function getCurrentUrl() { if (isset($_SERVER['HTTPS']) &amp;&amp; ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &amp;&amp; $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $protocol = 'https://'; } else { $protocol = 'http://'; } $currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parts = parse_url($currentUrl); $query = ''; if (!empty($parts['query'])) { // drop known fb params $params = explode('&amp;', $parts['query']); $retained_params = array(); foreach ($params as $param) { if ($this-&gt;shouldRetainParam($param)) { $retained_params[] = $param; } } if (!empty($retained_params)) { $query = '?'.implode($retained_params, '&amp;'); } } // use port if non default $port = isset($parts['port']) &amp;&amp; (($protocol === 'http://' &amp;&amp; $parts['port'] !== 80) || ($protocol === 'https://' &amp;&amp; $parts['port'] !== 443)) ? ':' . $parts['port'] : ''; // rebuild return $protocol . $parts['host'] . $port . $parts['path'] . $query; } protected function shouldRetainParam($param) { foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) { if (strpos($param, $drop_query_param.'=') === 0) { return false; } } return true; } protected function throwAPIException($result) { $e = new FacebookApiException($result); ?&gt; </code></pre> <p>CRON.php</p> <pre><code>&lt;?php require_once("src/facebook.php"); include("custom.php"); set_time_limit(0); $config = array(); $config['array'] = $appID; $config['secret'] = $appSecret; $facebook = new Facebook($config); $day = abs(date("j")); $month = abs(date("n")); $result = mysql_query("SELECT uid, uid2, name2 FROM birthdays WHERE birthmonth = '$month' AND birthday = '$day'"); while(($row = mysql_fetch_assoc($result)) &amp;&amp; mysql_num_rows($result)) { $link = $hostURL.'post.php?uid='.$row['uid'].'&amp;uid2='.$row['uid2']; $facebook-&gt;api('/'.$row['uid'].'/feed', 'POST', array( 'link' =&gt; $link, 'from' =&gt; '299185790135651', 'picture' =&gt; $hostURL.'image.php?id='.$row['uid2'], 'name' =&gt; 'Send Cake', 'message' =&gt; 'It\'s '.$row['name2'].'\'s birthday today! Send them a virtual cake!', 'caption' =&gt; 'Sponsored by Intercake Ltd' )); } ?&gt; </code></pre> <p>also... what is 'from' => '299185790135651', ?</p> <p>want to check my developer has put the right number here. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload