Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Exploring Google APIs with Python & JavaScript


Published on

Tech talk given at Silicon Valley CodeCamp in Oct 2015 and GDG New York in Nov 2016 to introduce developers to integrating with Google APIs from Python or JavaScript:

Want to integrate Google technologies into the web+mobile apps that you build? Google has various open source libraries & developer tools that help you do exactly that. Users who have run into roadblocks like authentication or found our APIs confusing/challenging, are welcome to come and make these non-issues moving forward. The first half of the talk covers the Google APIs Client Library, specifically with Python, although you could use any of the other languages supported. We'll then describe the steps necessary to create projects & enable Google APIs from the Google Developers Console. Then we discuss how to create & access the needed credentials. Code demos will show you how to use this code to talk to a variety of Google APIs. While you do the same thing using JavaScript, there is another developer tool that gives you access to Google APIs but in a slightly different way. The second half of the talk covers Google Apps Script, a self-contained JavaScript environment in the Google cloud. You'll learn what Apps Script is and how it's more like using "services" than traditional APIs. We'll show you how to use its development environment and create a Google Sheets spreadsheet that talks to several Google APIs. The applications you build, whether they use the Client Library or Apps Script are reachable by any client, browser, desktop/laptop or mobile. Learn how to leverage the power of Google technologies in the next apps you build!!

Published in: Technology
  • Be the first to comment

Exploring Google APIs with Python & JavaScript

  1. 1. Confidential & ProprietaryConfidential & Proprietary Exploring Google APIs with Python & JavaScript +Wesley Chun, @wescpy Developer Advocate Silicon Valley CodeCamp Oct 2015: San José, CA GDG New York City Nov 2016: New York, NY Contribute questions at: I teach
  2. 2. I write I code
  3. 3. Confidential & Proprietary Outline ● PART I: Overview of using Google APIs ○ Google Developers Console ○ Google APIs Client Library ○ Simple API key access to Google APIs ○ Authorized (OAuth2) access to Google APIs ○ Python code demos ■ Overview of boilerplate Python code (simple & authorized) ■ Demonstrate accessing 1-2 Google APIs ● PART II: Overview of Google Apps Script ○ Operating environment ○ Supported services ○ JavaScript code demos ■ Demonstrate accessing 1-2 Google APIs ● Summary (Materials derived from Launchpad Online video series [] content) Confidential & Proprietary Google APIs (Part I) & Google Apps Script (Part II)
  4. 4. PyCon May 2016: Portland, OR BayPIGgies Aug 2016: Mountain View, CA Exploring Google APIs with Python +Wesley Chun, @wescpy Developer Advocate Can't wait? pip{,3} install -U google-api-python-client AND SF Python project night Oct 2016: San Francisco, CA GDG NYC Nov 2016: New York, NY Contribute questions at: Outline ● Overview ● Getting started ● Python ● Live demo(?) ● Wrap-up
  5. 5. Part I: Google APIs overview
  6. 6. BUT ... wait, there’s more...
  7. 7. Part II: Getting Started with Google APIs Developers Console (devconsole)
  8. 8. OAuth2 scenarios ● Varies on application type (where apps located) ○ Web (server) applications ○ Installed (mobile & desktop computers) apps ○ Service accounts (cloud/server-to-server) ○ Client-side (JavaScript) apps ○ Limited-input devices (game consoles, printers, cameras, etc.) ○ ○ TODAY: command-line script == "Installed"
  9. 9. Part III: Using Google APIs with Python Open source client libraries for many languages, not just
  10. 10. SIMPLE AUTHORIZED API access Simple API access
  11. 11. General OAuth2 process ● Goal: valid access token == 3rd-party API data access ● How OAuth2 works (in general) ○ Step 1: Create OAuth2 credentials in DevConsole ○ Step 2: Send credentials to get access & refresh tokens ○ Step 3: Use access token to make authorized API calls ○ Step 4: Access tokens expire; use refresh to get new one ● ● Others will be similar (with slight differences) Authorized API access
  12. 12. SIMPLE AUTHORIZED Which do you choose? Part IV: Demo (live would make it interesting)
  13. 13. Searching Google+ for social posts Searching YouTube for videos
  14. 14. Listing your files in Google Drive Use of multiple APIs supported Simple, authorized, or a mix of both types of APIs; re-uses HTTP client; also see
  15. 15. Write your own or see (JS) Build a Node.js customized reporting tool with our Sheets API codelab at (JS)
  16. 16. Check out our Node.js Markdown-to-Google Slides sample app demoing the Slides API (JS)
  17. 17. Part V: Wrap-up
  18. 18. Reference ● Google Developers Console ○ ● Google APIs Client Library for Python (2 & 3) ○ pip{,3} install -U google-api-python-client ○ ■ .../python/guide/{django,google_app_engine} # special ● Other languages ○ Reference ● Blog + video Resources ○ SETUP & BOILERPLATE ■ (new Google APIs project setup) ■ (common Python boilerplate code review) ○ GOOGLE APIs ■ and (Google Drive API) ■ (Gmail API) ■ (Google Calendar API) ■ and (Google Sheets API) ■ (Google Slides API)
  19. 19. Alternative 1 ● Google Apps Script ○ What is it? ■ Executes as JavaScript in Google's cloud ■ Think “built-in” services vs. traditional API usage ■ Convenient access to G Suite/Google Apps data ■ Can also access other Google+external services ■ ○ Video resources ■ (Apps Script intro) ■ (Google Maps & Gmail APIs) ■ (YouTube [Data] API) ■ (Google Forms) Alternative 2 ● What about my favorite HTTP request library? ○ requests ■ ○ So can I use 'requests' to talk to Google APIs? ○ Answer: YES, but... ■ Not many examples out there ■ I found one at ■ BUT look at it, ~80% of code is auth{entic,oriz}ation ■ Client Library hides most of it from you ■ Summary: yes you can, but it'll be a DIY effort
  20. 20. Alternatives for other Google APIs ● Most, not all, Google APIs work with standard Client Library ● Other APIs/platforms have their own ○ Google AdWords ■ ○ Google Maps (Web Services) ■ ○ Google Cloud Platform ■ ○ Firebase platform (Android, iOS, Web, C++, Node.js, Java) ■ Thank you! Questions? +Wesley Chun @wescpy
  21. 21. Google Apps Script Accessing G Suite & other Google services with JavaScript +Wesley Chun, @wescpy Developer Advocate Silicon Valley CodeCamp Oct 2015: San José, CA GDG New York City Nov 2016: New York, NY Contribute questions at: Outline ● Background ● What Apps Script is/is NOT ● Supported services ● Use cases ● Example API usage ● Live demo(?) ● Wrap-up
  22. 22. Another Google secret? +JavaScript -API “flavor” +built-in “flavor” -OAuth2 (you)
  23. 23. JS Not your daddy’s JavaScript
  24. 24. Not Node.js either !=
  25. 25. Apps just the beginning Apps Script powers add-ons
  26. 26. Other Google services But wait, there’s more... Google Apps services Admin SDK Calendar Contacts Docs Drive Forms Gmail Google+ Domains Groups Maps Sites Sheets Tasks Other Google services AdSense Analytics BigQuery Fusion Tables Mirror (Glass) Prediction Translate YouTube Other services URL Fetch JDBC … and more…
  27. 27. Teachers’ tools Automation(i.e., mail merge)
  28. 28. Enterprise workflow(i.e., team OoO calendars) Types of Apps Scripts ● Standalone scripts ○ ○ Google Drive > Create > Script ● Add-ons (Docs, Sheets, Forms) & document-bound scripts ○ Tools > Script editor ○ Add-ons > Get/Manage add-ons ● Simple web apps & Sites-bound gadgets ○ More > Manage Site > Apps Scripts > Add new script
  29. 29. Your first Apps Script project
  30. 30. OAuth2 flow “Hello World” Apps Script intro video
  31. 31. JS
  32. 32. JS
  33. 33. JS Spreadsheet with code
  34. 34. Confidential & Proprietary Reference + next steps ● Developer videos and/or blogposts ○ (Apps Script intro) ○ (Google Maps & Gmail APIs) ○ (YouTube [Data] API) ○ (Google Forms) ● Documentation ○ ● Need help? ○ ● Community ○ Thank you! Questions? +Wesley Chun @wescpy
  35. 35. Confidential & Proprietary Summary ● We’ve created great technology but can’t build everything(!) ● APIs: our tech available for your apps to integrate with; free?!? ● Access using favorite dev tool via Google APIs Client Library ○ Python, JavaScript (client + Node.js), Java, C#/.NET, Go, Dart, Ruby, PHP ○ Also mobile samples in docs: Android (Java), iOS (Swift, Objective-C) ● Alternative: Google Apps Script ○ More like “built-in” services vs. traditional API usage (above) ○ Convenient access to G Suite/Apps data & other Google+external services ● Build the next great thing! Confidential & Proprietary Thank you! Questions? +Wesley Chun @wescpy slide deck