Programmatic login to facebook and message on the page (wall)

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.

+4
source share
3 answers

It looks like you need to update your status when you are offline from facebook. To do this, you need to access offline access to the application user, and you need to have an β€œinfinite” token for the facebook application to access the API so that your program can be updated at any time without logging in to facebook.

You can get something you want here

http://developers.facebook.com/docs/authentication/

+4
source

I'm a little late to the party here, but I thought I'd post my gist example in order to do something very similar, I added some functions to fbconsole to make programmatic login easier with fbconsole.automatically_authenticate to make access easier this information in a systematic manner. This add-on has not yet been included in the leading branch of fbconsole (it was just published this morning), but is available here in the meantime for those interested.

+1
source

This is what I use

  // = SET WALL DATA HERE =============== $attachment = array( 'access_token' => 'My Access token here', 'message' => '', 'name' => 'My Wall Post Header/Title Here', 'caption' => 'Small caption here', 'link' => 'http://www.mywebsite.org', 'description' => 'Wall Post Details Here', 'picture' => "http://www.mywebsite.org/images/logo.gif", ); // =POST ON FACEBOOK WALL ========================== $this->facebook->api('/me/feed', 'POST', $attachment); , $attachment); 

So, enable your Facebook API, get the Facebook Access token, SET data for your wall message and call facebook api with me / feed method.

This will make the wall on the wall without requesting entry.

make sure you use the correct access token.

0
source

Source: https://habr.com/ru/post/1379427/


All Articles