Note that there are some explanatory texts on larger screens.

plurals
  1. POphp post to facebook even if i'm logged out
    primarykey
    data
    text
    <p>I made this PHP script that fetches messages to be posted at regular intervals to a Facebook Page that I administer.</p> <p>My script is working fine, but depends on me as a user being logged into Facebook. I would like this script to run as a cron job so i fear the script will fail to work if i'm logged out.</p> <p>How can i make it work even if i'm not logged into Facebook?</p> <p>Note that I created a Facebook application as requested to be able to use the Facebook api. Is there a way to post as the Facebook application perhaps?</p> <p>Here is my code, in case it helps.</p> <pre><code>require_once('config.inc.php'); require '_classes/facebook-php-sdk/src/facebook.php'; $homeurl = 'http://domain.com/to-facebook/index.php'; $post_url = '/'.PAGEID.'/feed'; // The message $msg_body = array( 'message' =&gt; 'hello world', ); // Post to Facebook $facebook = new Facebook(array( 'appId' =&gt; FB_APP_ID, 'secret' =&gt; FB_APP_SECRET, )); // Get User ID $fbuser = $facebook-&gt;getUser(); if ($fbuser) { try { $postResult = $facebook-&gt;api($post_url, 'post', $msg_body ); } catch (FacebookApiException $e) { echo $e-&gt;getMessage(); } }else{ // I would like never to come to this point... $loginUrl = $facebook-&gt;getLoginUrl(array('redirect_uri'=&gt;$homeurl,'scope'=&gt;'publish_stream,manage_pages,publish_actions,status_update,offline_access')); header('Location: ' . $loginUrl); } if($postResult) { echo '&lt;h1&gt;Your message is posted on your facebook wall.&lt;/h1&gt;'; } </code></pre> <p><strong>* update *</strong> I tried the cronjob and unfortunately, after a while I had the "Error validating access token: Session has expired at unix time" message. I'm puzzled. What am i doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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