I have a website, and I need it to periodically send status updates to a Facebook page.
Using my personal Facebook account, I created an application and page. Until now, I could programmatically publish on my page by adding this code to my website:
include_once "lib/facebook/src/facebook.php"; $facebook = new Facebook(array('appId' => 'APP_ID_HERE', 'secret' => 'APP_SECRET_HERE')); if($facebook->getUser()) { try { $ret_obj = $facebook->api('/FACEBOOK_PAGE_ID_HERE/feed', 'POST', array( 'link' => 'www.example.com', 'message' => 'Posting with the PHP SDK!', 'access_token' => 'FACEBOOK_PAGE_ACCESS_TOKEN_HERE' )); echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>'; } catch(FacebookApiException $e) { // user logged out (has user_id, but invalid access token) $login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream')); echo 'Please <a href="' . $login_url . '">login.</a>'; } echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>'; } else { $login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream')); echo 'Please <a href="' . $login_url . '">login.</a>'; }
So, I just open my site, click "Log in", log in as I do. As soon as I register it, he will now be able to post a status update on his Facebook page.
Obviously, the problem here is that I need to log in so that it can send messages. If other users try to log in with their user accounts, my site will not be able to post status updates on the Facebook page, because I am the only administrator for the application / page.
My question is: do I have a way to programmatically log into Facebook so that I can automatically update these statuses on my page?
Sorry, the shared number is here for Facebook development.
source share