Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FacebookRequest::execute() not included in facebook sdk

After downloading facebook sdk for php i tried to run the following. The code is:

    function QueryToRetrieveUserThroughID(string $id) {

        $newFacebookApp = new Facebook\FacebookApp(app-id, app-secret);
        $request = new Facebook\FacebookRequest(
                $newFacebookApp, 'GET', '/' . $id
        );
         $response = $request->execute();
        $graphObject = $request->getGraphObject(); 
   }

Though when reaching the line $response = $request->execute(); it produces:

Fatal error: Uncaught Error: Call to undefined method Facebook\FacebookRequest::execute()

Am i doing something wrong here with the idea of how to use the API or indeed FacebookRequest::execute does not exist??

like image 872
J.Doo Avatar asked Sep 01 '16 10:09

J.Doo


1 Answers

It is actually an issue on Facebook for Developers page for Facebook SDK for PHP as described on Issue #509 wherein the sample codes on the page are actually for SDK v4, thus producing errors when used on v5.

An up-to-date documentation is hosted at https://github.com/facebook/php-graph-sdk/blob/5.5/docs/reference.md.

Using SDK v5:

// PHP GRAPH SDK 5.5
function QueryToRetrieveUserThroughID(string $id) {

    $newFacebook = new Facebook\Facebook([
        'app_id' => '{app-id}',
        'app_secret' => '{app-secret}',
        'default_graph_version' => 'v2.5',
    ]);

    $newFacebookApp = $newFacebook->getApp();
    $response = $newFacebook->get($id, '{access-token}');
    // or $response = $newFacebook->get($id);

    $graphObject = $response->getGraphObject();
}
like image 54
raymelfrancisco Avatar answered Oct 04 '22 05:10

raymelfrancisco