Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Facebook API for Kottans

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Facebook API for Kottans

Avatar for Andrei Sierkov

Andrei Sierkov

March 18, 2017

More Decks by Andrei Sierkov

Other Decks in Programming

Transcript

  1. Overview • App creation and set up • Facebook Login

    • Graph API • Facebook JS SDK • Creating sample app
  2. OAuth 2.0 and Facebook 1. YourApp registers on Facebook 2.

    User in YourApp clicks “login via FB” and browser redirects it to FB 3. User authorises access to his FB info for YourApp, YourApp gets access token that uses for requests to FB
  3. OAuth 2.0 +--------+ +---------------+ | |--(A)- Authorization Request ->| Resource

    | | | | Owner | | |<-(B)-- Authorization Grant ---| | | | +---------------+ | | | | +---------------+ | |--(C)-- Authorization Grant -->| Authorization | | Client | | Server | | |<-(D)----- Access Token -------| | | | +---------------+ | | | | +---------------+ | |--(E)----- Access Token ------>| Resource | | | | Server | | |<-(F)--- Protected Resource ---| | +--------+ +---------------+
  4. Check Login Status FB.getLoginStatus(function(response) {
 statusChangeCallback(response);
 }); // response status

    {
 status: ‘connected’, // connected || not_authorized || unknown
 authResponse: { // returns only if connected
 accessToken: '...',
 expiresIn:'...',
 signedRequest:'...',
 userID:'...'
 }
 };
  5. Graph API • The idea of a ‘social graph’ -

    information composed of: • nodes - basically "things" such as a User, a Photo, a Page, a Comment • edges - the connections between those "things", such as a Page's Photos, or a Photo's Comments • fields - info about those "things", such as a person's birthday, or the name of a Page
  6. /me Returns info about current user GET graph.facebook.com /me Returns

    info about current user’s photos GET graph.facebook.com /me/photos
  7. Choosing fields Returns id, name and picture of user GET

    graph.facebook.com /user_id_or_name?fields=id,name,picture
  8. Ordering Returns photo’s comments in reverse chronological order GET graph.facebook.com

    /{photo-id}? fields=comments.order(reverse_chronological)
  9. Nested requests and limits Returns 5 of current user’s albums

    (name and 2 it’s photos) and 5 posts GET graph.facebook.com /me? fields=albums.limit(5){name, photos.limit(2)}, posts.limit(5)
  10. Pagination • Cursor-based pagination {
 "data": [
 // Endpoint data

    is here
 ],
 "paging": {
 "cursors": {
 "after": "MTAxNTExOTQ1MjAwNzI5NDE=",
 "before": "NDMyNzQyODI3OTQw"
 },
 "previous": "https://graph.facebook.com/me/albums? limit=25&before=NDMyNzQyODI3OTQw"
 "next": "https://graph.facebook.com/me/albums? limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE="
 }
 } • Time-based pagination • Offset-based pagination
  11. Dialogs // Share to my wall FB.ui({
 method: 'share',
 href:

    'http://kottans.org',
 quote: 'Kottans are awesome!',
 }, (response) => {
 console.log('Share response', response);
 }); // Send a message FB.ui({
 method: 'send',
 link: 'http://kottans.org/kottans-calendar/',
 });
  12. Sample app • Stack • npm • ES Latest •

    Webpack • Babel • React • React-router • scss