Which Facebook SDK to use with PHP 5.3?

Unfortunately, I have reached a dead end. Due to various obsolete and other reasons, I cannot upgrade the system to PHP 5.4. And according to Facebook , I need 5.4 to run the latest SDK.

I am ready to accept a lower SDK, but:

  • Will I be ok if I use the old SDK?
  • Which SDK should I use?

Bonus question:

  1. What should change the composer path to use the old SDK? I currently have:

    "facebook / php-sdk-v4": "4.0. *"

+6
source share
4 answers

You can still use the old one: https://github.com/facebookarchive/facebook-php-sdk

Avi calls are the same. New - only recommended. You can even use your own CURL calls without the SDK.

You should use the latest version, but it might be a good idea to change your provider. PHP 5.4 should be the absolute minimum that any serious provider supports.

For old PHP you really don't need a composer. Just download it and install it on your server.

+2
source

You can still use the obsolete (but still working) facebookarchive / facebook-php-sdk .

And I don’t think this will change soon, because this code has been forked over 3,000 times on Github, and probably another ten thousand use it.

Here, successful user information is retrieved from the old PHP PHP SDK (tested on my server with PHP 5.3) -

It's 2016 and it still works - both as a Canvas callback and as an OAuth callback:

<?php require_once('facebook-php-sdk-3.2.3/src/facebook.php'); const TITLE = 'My amazing app'; const REDIRECT = 'https://example.com/myapp/'; $client = new Facebook(array( 'appId' => REPLACE_ME, 'secret' => REPLACE_ME, )); if (isset($_REQUEST['logout'])) { $client->destroySession(); header('Location: ' . REDIRECT); exit(0); } if ($client->getUser()) { try { $me = $client->api('/me?fields=id,first_name,gender'); $body = '<PRE>' . print_r($me, TRUE) . '</PRE>'; } catch (FacebookApiException $ex) { error_log($ex); $body = '<PRE>' . htmlspecialchars($e->getMessage()) . '</PRE>'; } } else { $body = sprintf('<P><A HREF="%s">Login</A></P>', $client->getLoginUrl()); } ?> <!DOCTYPE HTML> <HTML> <HEAD> <TITLE><?= TITLE ?></TITLE> </HEAD> <BODY> <?= $body ?> <P><A HREF="<?= REDIRECT ?>?logout">Logout</A></P> </BODY> </HTML> 

Do not forget -

  • Get app id and secret in Facebook console
  • Register the https://example.com/myapp/ callback as Canvas (and also optionally as a valid OAuth2 redirect URL) in the same place

Another alternative could be to use the Facebook SDK for JavaScript (here with jQuery):

 <!DOCTYPE HTML> <HTML> <HEAD> <TITLE><?= TITLE ?></TITLE> <SCRIPT SRC="//ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></SCRIPT> <SCRIPT> $(document).ready(function() { //$.ajaxSetup({ cache: true }); $.getScript('//connect.facebook.net/en_US/sdk.js', function() { FB.init({ 'appId' : '<?= APP_ID ?>', 'xfbml' : false, 'cookie' : true, 'status' : true, 'version': 'v2.6' }); FB.login(function(response) { if (response.authResponse) { console.log('Fetching your information.... '); FB.api('/me?fields=id,first_name,gender', function(response) { console.log(response); }); } else { console.log('User cancelled login or did not fully authorize.'); } }); }); }); </SCRIPT> </HEAD> <BODY> <?= $body ?> <P><A HREF="<?= REDIRECT ?>?logout">Logout</A></P> </BODY> </HTML> 

However, using the PHP SDK is preferable - because the information already exists (via POST or HTTP redirection), and since the JavaScript SDK shows a login pop-up window or darkens the page every time the page loads and actually requires the user to click it without browser blocking.

+2
source

No, you risk nothing using the old version of php-sdk. As noted, you can write your own curl instead of using the SDK. So my application was written before 2013.

0
source

Here's the old version:

 { "require": { "facebook/php-sdk" : "3.2.3" } } 

Then:

 php composer.phar require facebook/php-sdk:3.2.3 
-1
source

Source: https://habr.com/ru/post/982667/


All Articles