Search code examples
phpfacebookfacebook-php-sdk

Migrating to Facebook PHP SDK v4, Open Graph


I'm having an issue migrating this particular snippet

// previously

$facebook = new Facebook(array(
    'appId' => 'xxx',
    'secret' => 'xxx',
));

$accessToken = $facebook->getApplicationAccessToken();
$facebook->setAccessToken($accessToken);

$facebook->api($url, 'POST');

// v4.0
$session = Facebook\FacebookSession::newAppSession('xxx','xxx');

$response = (new Facebook\FacebookRequest(
    $session, 'POST', $url
))->execute();

And this is giving:

Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#803) Some of the aliases you requested do not exist: v2.0557210865'


Solution

  • $url should be /557210865 and not 557210865.