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??
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();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With