简体   繁体   中英

How To: Non-Facebook-Users post to Facebook page wall

I am thinking of a scenario and I need your opinions whether this is even possible.

I have a normal website, on this website I have a form and by sending the form it should be also sent to one specific facebook page. As a normal page status update. Now I do not want to force my users to register to facebook in order to send the form.

By reading some articles here and the facebook API I think this could be possible, but I have one problem I can not solve:

  1. Facebook app creation
  2. Getting user token of the admin
  3. Getting the page access token to post on the page wall

These points (1-3) should work fine, BUT here is my problem:

If I am right the token expires after some time - How is it possible to get a token which does not expire? Or are there some other ways to solve this problem?

This is the working code to post on the facebook page:

$attachment = array(
'access_token' => 'BACyul4fRfyEmI3xwMDs..........................',
'message'=> "Hello Test"
);
$result = $facebook->api('/'.$page_id.'/feed', 'POST', $attachment);

How is it possible to get a token which does not expire? Or are there some other ways to solve this problem?

It is not possible to get a token that does not expire, but they can be extended. Read here for more information. But the best practice is see if they are already logged in with the SDK, if they're not then redirect them to login. It's that simple.

You do not need to add an access_token in the attachment, the facebook SDK will handle that for you. So this is fine:

$attachment = array(
'message'=> "Hello Test"
);
$result = $facebook->api('/'.$page_id.'/feed', 'POST', $attachment);

More parameters are available in this documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM