Posting on a Facebook page with PHP SDK v5

Wednesday, November 4, 2015

I followed this guide to automatically post content to Facebook page.



Here is the sequence of steps:




  1. Check to see if the user is authorized to use the application

  2. Get single-use access token

  3. Back on a callback url and save a session called facebook_access_token

  4. In the last function, I establish the parameters for sending on Facebook. If I follow the guide above, I put :



    $data = array(
    'message' => 'Message',
    'link' => 'http://www.example.com',
    'picture' => 'http://www.example.com/images/test.png',
    'name' => 'Title',
    'caption' => 'www.example.com',
    'description' => 'Description'
    );

    # POST request in v5
    $response = $this->fb->post('/'.$this->appId.'/feed', $data, Session::get('facebook_access_token'));


    And I'm getting the following error :



    FacebookResponseException in FacebookResponseException.php line 108:
    Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api


    If I follow the Graph API Explorer directly proposed on the Facebook developers site, I put the same parameters as before (message, caption, etc ...) and then generates the code, I get this :



    $request = new FacebookRequest(Session::get('facebook_access_token'), 'POST', '/'.$this->appId.'/feed', array(
    'message' => 'Message',
    'link' => 'http://www.example.com',
    'picture' => 'http://www.example.com/images/test.png',
    'name' => 'Title',
    'caption' => 'www.example.com',
    'description' => 'Description'
    )
    );

    $response = $request->execute();
    $graphObject = $response->getGraphObject();


    Here I'm getting this error :



    ErrorException in FacebookUrlManipulator.php line 109:
    parse_url() expects parameter 1 to be string, array given



How to solve this problem?

0 comments:

Post a Comment