All about the new, NEW Facebook PHP SDK v4.1

All about the new, NEW Facebook PHP SDK v4.1

A 10 minute lightning talk presented at Nomad PHP on March 19th, 2015.

When developing on Facebook, things change all the time. And things are about to change once again with the release of the Facebook PHP SDK v4.1. It's got tons of new powerful features that have never existed in a Facebook PHP SDK before. This lightning talk is focused on giving a crash-course on the new Facebook PHP SDK v4.1 and it's features. By the end you should have the confidence to start using the new SDK within your own app.

8c090cc1ccd623a146ddd9159b1bf7e2?s=128

Sammy Kaye Powers

March 19, 2015
Tweet

Transcript

  1. 1.

    All About the By @SammyK For @nomadphp On March 19th,

    2015 new, NEW Facebook PHP SDK 4.1
  2. 7.

    OAuth 2.0 Client $authUrl = $provider->getAuthorizationUrl();! $_SESSION['oauth2state'] = $provider->state;! header('Location:

    '.$authUrl);! ! // . . .! ! $token = $provider->getAccessToken(! ! 'authorization_code', [! 'code' => $_GET['code']! ]);! $user = $provider->getUserDetails($token);! printf('Hello %s!', $userDetails->firstName);
  3. 8.

    Socialite Laravel 5 public function redirectToProvider() {! return Socialize::with(‘facebook')! !

    ! ! ->redirect();! }! ! public function handleProviderCallback() {! $user = Socialize::with(‘facebook')! ! ! ! ->user();! // $user->token;! }
  4. 9.

    • Signed request support • Easy-as-pie file uploads • Easy

    batch request support • Easy-peasy pagination • Graph Nodes as collections Facebook PHP SDK
  5. 14.
  6. 17.

    Facebook\Facebook() • Handles fall-back config • Factory for helpers &

    entities • Helps with HTTP requests • Container to inject custom deps
  7. 24.

    login from redirect $helper = $fb->getRedirectLoginHelper();! $login_link = $helper->! getLoginUrl(‘https://foo.com/fb');!

    ! echo '<a href="' . $login_link . '">'.! 'Log in!</a>'; Route: / Authentication
  8. 46.
  9. 48.
  10. 49.
  11. 55.
  12. 71.
  13. 75.

    $data = [! ! ! ‘message’ => ‘Hi from Nomad

    PHP!’,! ];! ! $res = $fb->post(‘/me/feed’, $data); $fb = Facebook\Facebook() Request & Response POST
  14. 81.

    Injectable Persistent Data Storage: `PersistentDataInterface` Injectable HTTP Client: `FacebookHttpClientInterface` Injectable

    CSPRNG: `PseudoRandomStringGeneratorInterface` Injectable URL detection: `UrlDetectionInterface` Advanced Integration
  15. 83.

    $data = [
 'message' => 'My awesome photo.',
 'source' =>

    $fb->fileToUpload('/my/photo.jpg'),
 ];! ! $res = $fb->post(‘/me/feed’, $data); $fb = Facebook\Facebook() File Uploads Photo example
  16. 84.

    $data = [! 'title' => 'My video’,
 'description' => 'My

    awesome video.',
 'source' => $fb->videoToUpload('/my/photo.mp4'),
 ];! ! $res = $fb->post(‘/me/feed’, $data); $fb = Facebook\Facebook() File Uploads Video example
  17. 87.