简体   繁体   中英

Is it possible Facebook PHP SDK 4.0 and Graph API v2.8?

I am using Facebook PHP SDK 4.0 along with Graph API v2.2. I wondered if it is possible to use Graph API v2.8 with this PHP SDK 4.0 (I've got PHP 5.2 installed on my server and I can not use PHP SDK 5.0).

Currently, I use the following code to obtain the user ID

$facebook = new Facebook(array(
  'appId'  => $facebookAppId,
  'secret' => $facebookSecret
));
$user = $facebook->getUser();
if ($user) {
    $user_profile = $facebook->api('/me');
    $user_id = $user_profile['id'];
}

I was warned that the API v2.2 will be deprecated late this month, and I am trying to migrate my code to API v2.8.

Thank you very much.

// Initialize the Facebook PHPSDK5 and v2.8.

$fb = new Facebook\Facebook([
  'app_id'                => 'xxxxxxxxxxxx',
  'app_secret'            => 'xxxxxxxxxxxxxxxxxxxxxxxx',
  'default_graph_version' => 'v2.8',
]);

$helper = $fb->getRedirectLoginHelper();
try {
  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // There was an error communicating with Graph
  echo $e->getMessage();
  exit;
}

if (isset($accessToken)) {
  // Logged in.
  $_SESSION['facebook_access_token'] = (string) $accessTokenLong;
}

$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);

$me = $fb->get('/me');
$me_array = $me->getGraphEdge()->asArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM