Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
An entertaining intro to Graph Theory, the Face...
Search
SammyK
February 07, 2015
Education
230
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
An entertaining intro to Graph Theory, the Facebook Platform and the new, NEW PHP SDK
An uncon talk at Sunshine PHP 2015
SammyK
February 07, 2015
More Decks by SammyK
See All by SammyK
Going Bare - Writing The Web Without A Framework - Longhorn PHP 2019
sammyk
1
1.3k
Going bare - writing the web without a framework - php[world] 2018
sammyk
0
780
The Debug Dance - An Intro To Step Debugging - php[world] 2018
sammyk
0
1.6k
Let's get random: Under the hood of PHP 7's CSPRNG - ZendCon & OpenEnterprise 2018
sammyk
0
1.8k
The debug dance: An intro to step debugging - ZendCon & OpenEnterprise 2018
sammyk
1
530
Going Bare - Writing the web without a framework - Cascadia PHP 2018
sammyk
0
920
Let's Get Random - Under The Hood of PHP 7's CSPRNG - php[tek] 2018
sammyk
0
340
Writing Tests For PHP Source - ZendCon 2017
sammyk
1
1.8k
Going Bare - Writing the web without a framework - ZendCon 2017
sammyk
2
560
Other Decks in Education
See All in Education
良書紹介08_ 頭のいい子がやっているすごいグラフの読み方
bunnchinn3
0
160
医療事務養成の専門学校でのAI教育 非エンジニアの学生にAIを1年間使ってもらって、感じたこと
naochim2026
0
120
[2026前期火5] 論理学(京都大学文学部 前期 第12回)「証明を走らせる:カリー・ハワード対応」
yatabe
0
320
[2026前期火5] 論理学(京都大学文学部 前期 第14回)「計算は、証明ではない——ハルシネーションを三層ハーモニーで診る」
yatabe
0
270
Center for Entrepreneurship Education | Science Tokyo (Institute of Science Tokyo)
sciencetokyo
PRO
0
410
未踏峰連山 Frontiers: Creating and Conquering Untrodden Peaks
ishii_mit
1
120
AIがコードを書く時代に、何を教えるのか / What Should We Teach in the Age of AI-Generated Code?
ichiroc
1
560
Fundamentos, Caracteristicas y Aplicaciones de los Modulos NumPy , Matplotlib y Pandas
robintux
0
260
学生のうちに考えておきたい信頼の話
suisan
1
800
Introduction - Lecture 1 - Web Technologies (1019888BNR)
signer
PRO
0
6.5k
AIの力を100%引き出すために
frievea
0
520
20260908_ターゲットとスコープを決める発表法
masakiokuda
1
120
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Designing Experiences People Love
moore
143
24k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Tell your own story through comics
letsgokoyo
1
1.1k
Exploring anti-patterns in Rails
aemeredith
4
510
The Cult of Friendly URLs
andyhume
79
7k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
230
The agentic SEO stack - context over prompts
schlessera
0
940
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
460
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Transcript
Sammy Kaye Powers February 7th, 2015 new, new An entertaining
intro to Platform Graph theory Facebook the and the PHP SDK
Does not work @
Goal overview To get an
photo: harryritchies.com History lesson A slightly embellished
1736 The year is
People wore Funny Bathing suits
riddles People solved
like this one
seven bridges
seven bridges Here
seven bridges Here Here
seven bridges Here Here Here
seven bridges Here Here Here Here
seven bridges Here Here Here Here Here
seven bridges Here Here Here Here Here Here
seven bridges Here Here Here Here Here Here There
cross all the bridges ONCE and only once?
None
enter Leonhard Euler
invents Graph theory
uses graph theory to Answer
No.
None
268 Fast-forward years…
Facebook is Born! photo: bzd1 on Flickr
I guess I should back up a bit…
Graph Theory What is
Describes rela tion ships
Guitars haveStrings
David likes pickles
to model relations Graphs we use
Graph? What kind of
This?
Nope This?
This?
Nope This?
This?
Nope This?
This?
Nope This?
Aw, kitty…
So what kind?
This
A simple graph
Dots
Dots Lines
Dots Lines
Nodes Lines
Nodes Lines a.k.a vertices
Nodes Lines a.k.a vertices
Nodes Edges a.k.a vertices
None
A “Thing”
the relation between the things
In the Back-end uses graph theory
Social Graph It’s called the
Social Graph It’s called the
…as in the Graph Theory kind of graphs
Social Graph photo: uberhumor.com
Social Graph It’s called P.S. That’s the open graph logo
(a little different)
Describing this with Social Graph
None
None
Jordan
Jordan
Tatiana Jordan
Tatiana Jordan
Tatiana Jordan Kisses
Tatiana Jordan Kisses (instances of kissing)
Tatiana Jordan Kisses
Scott Tatiana Jordan Kisses
Scott Tatiana Jordan Kisses
Scott Tatiana Jordan stalks Kisses
Scott Tatiana Jordan stalks Kisses (instances of stalking)
Scott Tatiana Jordan Kisses stalks
Scott Tatiana Jordan stalks Kisses stalks
Scott Tatiana Jordan stalks Kisses stalks
Scott Tatiana Jordan stalks Kisses stalks people stalking people
“Facebooky” example
None
Social Graph (Facebook)
PHP Nerd (you) (Facebook) Social Graph
(you) (Facebook) ?? link ?? Social Graph PHP Nerd
(you) (Facebook) Graph API Social Graph PHP Nerd
(you) (Facebook) Graph API Hi! Social Graph PHP Nerd
(you) (Facebook) Graph API Social Graph PHP Nerd
<tangent>
AN API? What’s
application program interface
specifies how software components should interact
API Laravel $user = DB::table(‘users')! !!!->where('name', ‘John')! !!!->first();
Http protocol API’s over the
HTTP API over Host: silly.com! ! GET /users/123
HTTP API over HTTP/1.1 200 OK! Content-Type: application/json! ! {!
!“id”: 123,! !“name”: “Foo User”! }
Web API’s These are
API Graph API The is a Web
API’s Web • REST! • HATEOAS! • OAuth! • etc…
Graph API The • REST! • HATEOAS! • OAuth! •
etc…
Graph API The • REST! • HATEOAS! • OAuth! •
etc… Nope
Graph API The • REST! • HATEOAS! • OAuth! •
etc… Nope Nope
Graph API The • REST! • HATEOAS! • OAuth! •
etc… Nope Nope ✓ Yep! (2.0)
Graph API The • REST! • HATEOAS! • OAuth! •
etc… Nope Nope ✓ Yep! (2.0) Don’t have to know!
</tangent>
PHP App Graph API Social Graph
Graph API Can I haz user 123? Social Graph PHP
App
Graph API Can I haz user 123? Can I haz
user 123? Social Graph PHP App
Graph API Yes: Social Graph PHP App
Graph API Yes: {! name “Scott”,! title: “Creeper”! } Social
Graph PHP App
Graph API tl;dr
https://! graph.facebook.com Lives here
/v2.2/foo-bar URL prefix versioned with a
Not RESTful so developers be like
OAuth 2.0 Uses a flavor of Don’t have to know!
Every “Thing”…
Users Every “Thing”…
comments Users Every “Thing”…
photos comments Users Every “Thing”…
photos comments Users Nodes Every “Thing”…
photos comments Users Nodes Every “Thing”… Yay! Nodes!
A photo A comment A User Nodes id:12..3 id:”45_90” id:45..90
Every “Thing”…
A little Weird ID’s are
id:972343284723449 A User A little Weird ID’s are
id:972343284723449 A comment A User id:”45_90” A little Weird ID’s
are
Graph API request/response
photo id:4590
photo id:4590 Host: graph.facebook.com! GET /v2.2/4590
photo id:4590 Shouldn’t That Be /v2.2/photos/4590 ??? Host: graph.facebook.com! GET
/v2.2/4590
photo id:4590 HTTP/1.1 200 OK! {! "id": "4590", ! "name":
"Plane!", ! . . .! } Host: graph.facebook.com! GET /v2.2/4590
Nodes a list of
comments Nodes a list of a list of
comments Nodes a list of Likes a list of a
list of
photos comments Nodes a list of Likes a list of
a list of a list of
photos comments Nodes a list of Likes Edges
/v2.2/node/edge come after Edges Nodes
photo id:4590
photo id:4590 comments
photo id:4590 GET /v2.2/4590/comments comments
photo id:4590 GET /v2.2/4590/comments HTTP/1.1 200 OK! ! {"data": [!
{"id": "4590_123",! "message": "Pickles!"},! {"id": "4590_456", ! "message": "Turtles!"}! ]} comments
Nodes have and fields edges
Graph API endpoint reference developers.facebook.com/! docs/graph-api/reference
User Node fields edges - id! - first_name! - last_name!
- name! - email * /albums! /feed! /photos! /friends! /picture *
a note on permissions
Request GET /v2.2/123/turtles Graph API the
GET /v2.2/123/turtles be like Graph API
GET /v2.2/123/turtles be like Developers
B.T.Dubs… GET /v2.2/123/turtles
B.T.Dubs… GET /v2.2/123/turtles not a valid Edge
But! GET /v2.2/123/photos legit Edge
GET /v2.2/123/photos HTTP/1.1 200 OK! ! {"data": []} empty Response
GET /v2.2/123/photos user_photos Permission you’ll need the
GET /v2.2/123/photos login ask for permissions at (more on this
later)
GET /v2.2/123/photos HTTP/1.1 200 OK! ! {"data": []} empty Response
How do we access the Graph API
With a Facebook App
but first…
Become a Developer
developers.facebook.com
developers.facebook.com
developers.facebook.com
developers.facebook.com
Three important points
1. Read the Platform Policy Three important points
1. Read the Platform Policy 2. Read the Platform Policy
Three important points
1. Read the Platform Policy 2. Read the Platform Policy
3. Read the Platform Policy Three important points
None
Yay! Now you’re a Developer
Creating a Facebook App
None
None
None
None
App Dashboard
Yay! You created a Facebook app
App Dashboard
App Settings
Anatomy of a Facebook App
None
Core
Core (not an official term)
Platforms Platforms
Core Facebook App
None
ID
Name ID
Secret Name ID
Secret Name ID
App Name Created by you
App Name My Awesome App Example:
App Id Numeric identifier
App Id Created by Facebook
App Id Doesn’t have to be secret
App Id 111417252289428 Example:
App Secret Created by Facebook
App Secret Used to validate data from Facebook
Secret!! App Secret Don’t show it to anyone who doesn’t
need it
App Secret
Platforms Facebook App
None
Website
Website Canvas
Website Canvas Mobile
Website Canvas Page Tab Mobile
Website Canvas Page Tab Mobile ConSole
App Settings
App Settings
App Settings
Compare with new app
Website To configure Facebook Login Log in with Facebook
Website To configure Facebook Login Log in with Facebook
CANVAS To configure canvas apps
like…
None
CANVAS Canvas is just <iframe src=“”></iframe>
Page Tab To configure Page tabs
None
Page Tab Page tab is just <iframe src=“”></iframe>
Mobile For native mobile apps
P.S.
Remember what’s under there?
Ah?
Ah?
Ah?
Secret!!
Cereally guys… Secret!!
One last thing before we code…
Understanding Facebook Login
Login Flow • User clicks on link • Facebook asks
to approve • Access token is obtained *
All about Access Tokens
Access Tokens look like CAACEdEose0cBAJHwVI2DydR M65PZAld1a8r2efvhZBEruyv TTr87xjR85sIrFYeZBzsh5WZ CpO5wrVxZAO6JDmf3a5mL…
Access Tokens are sent with API requests GET /v2.2/123?! !!!
!access_token=CAACE…
Access Tokens Represent
Access Tokens Represent A User
Access Tokens Represent A User A Page
Access Tokens Represent A User An App A Page
Access Tokens Represent A User An App A Page Graph
API
Access Tokens Represent A User An App A Page
App Access Tokens are concatenated from
App Access Tokens are concatenated from
App Access Tokens are concatenated from + |
App Access Tokens are concatenated from + | +
+ | + Example: 123 appsecret
+ | + 123|appsecret Example: 123 appsecret
+ | + 123|appsecret Example: 123 appsecret But Wait!
+ | + 123|appsecret Example: 123 appsecret
Access Tokens have two lifetimes
Short-Lived Access Tokens have two lifetimes (default)
Short-Lived Long-Lived Access Tokens have two lifetimes (default)
Short-Lived Long-Lived Access Tokens have two lifetimes (default) 2 hours
Short-Lived Long-Lived Access Tokens have two lifetimes (default) 60 Days
2 hours
Access Tokens request cycle Graph API
Access Tokens request cycle Graph API Can I haz Access
Token?
Access Tokens request cycle Graph API Short-Lived
Access Tokens request cycle Graph API ThX, but… Can I
HAz Longer? Short-Lived
Access Tokens request cycle Graph API Long-Lived
You haz Access token! …now send requests to the Graph
API
Sound Complicated?
Sound Complicated? There’s An SDK For That
Facebook App Graph API So far… Facebook Dev Facebook Login
Facebook App Graph API So far… Facebook Dev Facebook Login
✓
Facebook App Graph API So far… Facebook Dev Facebook Login
✓ ✓
Facebook App Graph API So far… Facebook Dev Facebook Login
✓ ✓ ✓
Facebook App Graph API So far… Facebook Dev Facebook Login
✓ ✓ ✓ ✓
Facebook App Graph API So far… Facebook Dev Facebook Login
✓ ✓ ✓ ✓ Now What?
Facebook App Graph API So far… Facebook Dev Facebook Login
✓ ✓ ✓ ✓ Code Time!
Software development kits (SDK’s)
Two official SDK’s we care about
Two official SDK’s we care about php
Two official SDK’s we care about php Javascript
Two official SDK’s we care about php Javascript
v4.1 php SDK
php SDK v4.1 Do I even Need This?
OAuth 2.0 Remember… Facebook Login uses
Clients OAuth 2.0 PHP League $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);
Clients OAuth 2.0 Laravel 5 public function redirectToProvider() {! return
Socialize::with(‘facebook')! ! ! ! ->redirect();! }! ! public function handleProviderCallback() {! $user = Socialize::with(‘facebook')! ! ! ! ->user();! // $user->token;! }
php SDK v4.1
php SDK v4.1 Heads up
php SDK v4.1 • Handles login flow • Graph Nodes
as collections • Signed request support • Easy-as-pie file uploads • Easy batch request support • Easy-peasy (deep) pagination
Install "require": {! "facebook/php-sdk-v4":! "~4.1.0@dev"! } composer.json
Install "require": {! "facebook/php-sdk-v4":! "~4.1.0@dev"! } composer.json
Config $fb = new Facebook\Facebook([! /* */! ]);
Config $fb = new Facebook\Facebook([! 'app_id' => 'app-id',! 'app_secret' =>
'secret',! ]);
Config $fb = new Facebook\Facebook([! 'app_id' => 'app-id',! 'app_secret' =>
'secret',! ]); SECRET! better: use env vars
Config $fb = new Facebook\Facebook(); if you have env vars
FACEBOOK_APP_ID FACEBOOK_APP_SECRET and
Facebook Login
login from redirect $login_link = $fb->getLoginUrl();! ! echo '<a href="'
. $login_link . '">'.! 'Log in!</a>'; Route: / php SDK v4.1
login from redirect $login_link = $fb->getLoginUrl([! 'email',! 'user_status',! ]); Route:
/ php SDK v4.1
callback URL Route: /facebook/login $token =! $fb->getAccessTokenFromRedirect(); php SDK v4.1
callback URL $token =! $fb->getAccessTokenFromRedirect(); Route: /facebook/login throws Facebook\Exceptions \FacebookSDKException
php SDK v4.1
callback URL use Facebook\Exceptions\FacebookSDKException;! try {! $token = $fb->getAccessTokenFromRedirect();! }
catch (FacebookSDKException $e) {! dd(‘Error:' . $e->getMessage());! } Route: /facebook/login php SDK v4.1
$token once you obtain user is logged in! :) (sort
of…) php SDK v4.1
$token what do you do with php SDK v4.1
Store it for later… session Database $token php SDK v4.1
User Data Getting
Getting User Data $res = $fb->get(‘/123’, $token); Facebook\Facebook()
Getting User Data $res = $fb->get(‘/123’, $token); User node id
Facebook\Facebook()
Getting User Data $res = $fb->get(‘/123’, $token); Can set Default
Facebook\Facebook()
Getting User Data $fb->! setDefaultAccessToken($token);! $res = $fb->get(‘/123’); Set As
Default Facebook\Facebook()
Getting User Data $fb->! setDefaultAccessToken($token);! $res = $fb->get(‘/123’); don’t need
Facebook\Facebook()
Getting User Data $res = $fb->get(‘/123?! fields=id,name,email’); Facebook\Facebook()
Getting User Data $res = $fb->get(‘/123’); Facebook\FacebookResponse() Facebook\Facebook()
Getting User Data $a = $res->getHttpStatusCode();! $b = $res->getHeaders();! $c
= $res->getBody();! $d = $res->getDecodedBody(); Facebook\FacebookResponse()
Getting User Data $node = $res->getGraphObject(); Facebook\FacebookResponse() Facebook\GraphNodes\GraphObject()
Getting User Data $node = $res->getGraphObject(); Facebook\FacebookResponse() Facebook\GraphNodes\GraphObject() Heads up
Getting User Data $node = $res->getGraphNode(); Facebook\FacebookResponse() Facebook\GraphNodes\GraphNode() Heads up
Getting User Data Facebook\! GraphNodes\! GraphNode() extends from a collection
Getting User Data GraphUser! GraphPage! GraphAlbum Facebook\GraphNodes\GraphNode() sub nodes of
namespace: Facebook\GraphNodes $res->getGraphUser();! $res->getGraphPage();! $res->getGraphAlbum();
Remember way back when…
User Node fields edges - id! - first_name! - last_name!
- name! - email * /albums! /feed! /photos! /friends! /picture *
Getting User Data $id = $userNode->getId();! $name = $userNode->getName();! $partner
=! $userNode->getSignificantOther(); Facebook\GraphNodes\GraphUser()
User’s Timeline Posting on a
Getting User Data $data = [! ! ! ‘message’ =>
‘Hello from #ssp15’,! ];! ! $res = $fb->post(‘/me/feed’, $data); Facebook\Facebook()
Getting User Data $data = [! ! ! ‘message’ =>
‘Hello from #ssp15’,! ];! ! $res = $fb->post(‘/me/feed’, $data); Facebook\Facebook()
WEB Framework Custom persistent store URL detection HTTP Client Tying
into
*Phew* time for a kitty break
SDK Javascript Sharing with the
Javascript SDK installation <script>! window.fbAsyncInit = function() {! FB.init({! appId
: 'your-app-id',! xfbml : true,! version : 'v2.1'! });! };! ! (function(d, s, id){! var js, fjs = d.getElementsByTagName(s)[0];! if (d.getElementById(id)) {return;}! js = d.createElement(s); js.id = id;! js.src = "//connect.facebook.net/en_US/sdk.js";! fjs.parentNode.insertBefore(js, fjs);! }(document, 'script', 'facebook-jssdk'));! </script> copy/paste before developers.facebook.com/docs/javascript/quickstart </body>
Javascript SDK installation <script>! window.fbAsyncInit = function() {! FB.init({! appId
: 'your-app-id',! xfbml : true,! version : 'v2.1'! });! };! ! (function(d, s, id){! var js, fjs = d.getElementsByTagName(s)[0];! if (d.getElementById(id)) {return;}! js = d.createElement(s); js.id = id;! js.src = "//connect.facebook.net/en_US/sdk.js";! fjs.parentNode.insertBefore(js, fjs);! }(document, 'script', 'facebook-jssdk'));! </script> developers.facebook.com/docs/javascript/quickstart This
Javascript SDK installation FB.init({! appId : '{your-app-id}',! cookie : true,!
version : 'v2.2'! });
Javascript SDK installation FB.init({! appId : '{your-app-id}',! cookie : true,!
version : 'v2.2'! });
Javascript SDK share dialog FB.ui({! method: 'share',! href: ‘http://foo.com'! },
function(response){});
Javascript SDK share dialog FB.ui({! method: 'share',! href: 'http://foo.com'! },
function(response){});
Javascript SDK share dialog
Javascript SDK share dialog Customize?
Javascript SDK share dialog FB.ui({! method: 'share',! href: 'http://foo.com'! },
function(response){});
meta tags Open Graph
meta tags <meta property=“og:url"! content="http://foo" /> ! <meta property=“og:title"! content=“Foo
Site" />! <meta property=“og:description"! content=“Foo description of bar" /> ! <meta property=“og:image"! content=“http://foo.c/bar.jpg” /> Open Graph
meta tags <meta property=“og:url"! content="http://foo" /> ! <meta property=“og:title"! content=“Foo
Site" />! <meta property=“og:description"! content=“Foo description of bar" /> ! <meta property=“og:image"! content=“http://foo.c/bar.jpg” /> Open Graph
meta tags <meta property=“og:url"! content="http://foo" /> ! <meta property=“og:title"! content=“Foo
Site" />! <meta property=“og:description"! content=“Foo description of bar" /> ! <meta property=“og:image"! content=“http://foo.c/bar.jpg” /> Open Graph
meta tags <meta property=“og:url"! content="http://foo" /> ! <meta property=“og:title"! content=“Foo
Site" />! <meta property=“og:description"! content=“Foo description of bar" /> ! <meta property=“og:image"! content=“http://foo.c/bar.jpg” /> Open Graph
Learn? What did we
Before you cAme
Know You prolly didn’t
Know You prolly didn’t Graph API
Know You prolly didn’t Graph API Facebook Developer
Know You prolly didn’t Facebook App Graph API Facebook Developer
Know You prolly didn’t Facebook App Graph API Facebook Developer
Facebook Login
Know You prolly didn’t Facebook App Graph API Facebook Developer
Facebook Login Access Tokens
Know You prolly didn’t Facebook App Graph API Facebook Developer
Facebook Login Access Tokens php SDK
Know You prolly didn’t Facebook App Graph API Facebook Developer
Facebook Login Access Tokens Javascript SDK php SDK
Now Look at you!
Now Look at you! Yay! Learning!
Learn! So much more to • Graph API • User
Permissions • App Canvas • Page Tabs • Test Users • Test Apps • And more!
Next Steps Create an app & play!
Next Steps March 25 & 26 San Francisco
THANKS! Sammy Kaye Powers @SammyK SammyK.me Host of @PHPRoundtable Chicago
Facebook Developers West Coast Swing