Jump to content

[Laravel5] Post links to my Facebook page as the page itself


Kumidan

Recommended Posts

I've got a website where users can fill a form, the web application stores the data into the database.
Those data are used to create contents on the site.
As a user submits the form, I want to post a link to the Facebook page related to the website, but not in name of the user, but as the page itself.
I've read a lot of tutorials around, but I couldn't have this working.
This is my code at the moment, but of course it doesn't work

FacebookSession::setDefaultApplication($app_id, $app_secret);

$session = FacebookSession::newAppSession();

try {
    $session->validate();
} catch (FacebookRequestException $ex) {
    echo $ex->getMessage();
} catch (\Exception $ex) {
    echo $ex->getMessage();
}

if($session)
{
    try {
        $response = (new FacebookRequest(
            $session, 'POST', '/me/feed', array(
                'link' => 'www.mysite.it',
                'message' => 'some text'
            )
        ))->execute()->getGraphObject();
        echo "Posted with id: " . $response->getProperty('id');
    } catch(FacebookRequestException $e) {
        echo "Exception occured, code: " . $e->getCode() . 
             " with message: " . $e->getMessage();
    }
}

What I get is this error message:

"Exception occured, code: 2500 with message: An active access token must be used to query information about the current user."

 

As I've understood I miss to login as the page, but I can't uderstand how to do so.
Could any one tell me how to chenge the code?

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.