Graph API Reporter

Paulo Ávila

24 Aug 2017

Google Sheets Add-on

About Me

  • Partner Engineer @ Facebook
    • Instagram Platform
    • Internet.org (Free Basic Services)
    • Media Partnerships

Agenda

     Motivation

     What does it do?

🐢 Evolution

🚧 Problems encountered

💡 Solutions

👾 Demo!

❓ Questions

Inspiration and Motivation

  • Instant Articles gathers native insights

  • Native insight reporting lacking

  • Technical integrations required

  • Extensible

"That's possible but only through the API"

Graph API Explorer

GET /1731770190373618
      ?fields=instant_articles_insights
                .metric(all_views)
                .period(day)
                .since(2017-08-15)
                .until(2017-08-22)

Approachable UI

{
  "instant_articles_insights": {
    "data": [
      {
        "name": "all_views",
        "time": "2017-04-06T08:00:00+0000",
        "value": "16",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-06T08:00:00+0000",
        "value": "31",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-07T08:00:00+0000",
        "value": "8",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-07T08:00:00+0000",
        "value": "21",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-08T08:00:00+0000",
        "value": "2",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-08T08:00:00+0000",
        "value": "8",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-09T08:00:00+0000",
        "value": "4",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-09T08:00:00+0000",
        "value": "4",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-10T08:00:00+0000",
        "value": "3",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-11T08:00:00+0000",
        "value": "2",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-11T08:00:00+0000",
        "value": "3",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-12T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-12T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-14T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-16T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-17T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-19T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-25T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-29T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "ANDROID"
        }
      },
      {
        "name": "all_views",
        "time": "2017-04-29T08:00:00+0000",
        "value": "1",
        "breakdowns": {
          "platform": "IOS"
        }
      }
    ]
  },
  "id": "1731770190373618"
}

Tables and charts ;-)

What does it do?

  • Does
    • Brings Facebook data into Google Sheets
  • Allow
    • Programmatic interaction with the Facebook Graph API
  • Enable
    • Generation of custom reports

😭

Meet: FbLoginSdk for
Google Apps Scripts!

  • Substitutes Facebook’s Login SDK

  • Pre-configures apps-script-oauth2 lib

  • Normalises interface to the Facebook Graph API

    • API version between oauth and API calls

    • Guard to intercept unauthorised calls

    • Fetch/parse results through simplified interface

  • Built-in FB Login dialog

  • Debug info about logged in session


// Initializes the SDK and OAuth2 service.
FB.init({
  appId: '165010617304976',
  appSecret: '################################',
  version: 'v2.8'
});


// Generates the oauth URL for Login process
FB.getLoginUrl(['manage_pages']);
// facebook.com/dialog/oauth?client_id=165010617304976& [...] &scope=manage_pages


// Makes a request to the Facebook API.
FB.api('/me?fields=id,name');
// {
//   "id": "10101376964838285",
//   "name": "Paulo Ávila"
// }
<script>
// Dialog re-focussed.
// Usually upon returning from Facebook Login.
window.addEventListener('focus', function returnedFromOAuth() {

  google.script.run
  .withSuccessHandler(function (isLoggedIn) {

    // Return from FbSdkIsLoggedIn() is true.
    if (isLoggedIn) {

      // Execute the queued-up callback action
      // which is a function name as a string passed in to this template file.
      try {
        google.script.run.<?!= postLoginAction ?>();
        google.script.host.close();
      } catch(e) {}
    } else {
      // Not actually logged.
    }
  })
  .FbSdkIsLoggedIn();

});
</script>

Logged Out Guard

Demo

Drawbacks

  • Disconnected from native Facebook UI

  • Cross-pollination between Google::Facebook

  • Reports need to be pre-programmed

    • (configurable, not customisable)

  • FbLoginSdk

    • Non-standard, atypical flow

To-Do

  • Automated reporting via email

  • Additional reports:

    • Top N articles (batch requesting)

    • Month-over-month

    • Instant Articles Newsletter Signup Leads export

Questions

Made with Slides.com