CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2007
    Location
    Italia
    Posts
    45

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

    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

    PHP Code:
    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?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: [Laravel5/FB] Post links to my Facebook page as the page itself

    In initializing a new app session, you have to provide the access token you've acquired via the login API...which you're not doing.

    Make sure you have all the required files and trade out your $session line for the following.

    PHP Code:
    $loginHelper = new FacebookRedirectLoginHelper('YOUR SITE URL');
    try {
      
    $session $loginHelper->getSessionFromRedirect();
    }
    catch (
    FacebookRequestException $e) {
      echo 
    "Exception occured, code: " $e->getCode();
      echo 
    " with message: " $e->getMessage();
    }
    catch (
    Exception $e) {
      echo 
    'Error';
    }

    if (!isset(
    $session)) {
      
    header('Location: ' $loginHelper->getLoginUrl(array('scope' => 'YOUR APP SCOPES')));
      exit;

    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured