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

1,104 views

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: https://www.siliconvalley-codecamp.com/Session/2015/exploring-google-apis-with-python-and-javascript

ABSTRACT
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: goo.gl/Rq6ABI 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 [goo.gl/kFMUa6] 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 console.developers.google.com SF Python project night Oct 2016: San Francisco, CA GDG NYC Nov 2016: New York, NY Contribute questions at: goo.gl/Rq6ABI 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.) ○ developers.google.com/identity/protocols/OAuth2 ○ TODAY: command-line script == "Installed"
  9. 9. Part III: Using Google APIs with Python developers.google.com/discovery/libraries 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 ● developers.google.com/identity/protocols/OAuth2 ● 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 goo.gl/cdm3kZ
  15. 15. Write your own or see github.com/googledrive/zipextractor (JS) Build a Node.js customized reporting tool with our Sheets API codelab at g.co/codelabs/sheets (JS)
  16. 16. Check out our Node.js Markdown-to-Google Slides sample app demoing the Slides API github.com/googlesamples/md2googleslides (JS)
  17. 17. Part V: Wrap-up
  18. 18. Reference ● Google Developers Console ○ console.developers.google.com ● Google APIs Client Library for Python (2 & 3) ○ pip{,3} install -U google-api-python-client ○ developers.google.com/api-client-library/python ■ .../python/guide/{django,google_app_engine} # special ● Other languages ○ developers.google.com/discovery/libraries Reference ● Blog + video Resources ○ SETUP & BOILERPLATE ■ goo.gl/RbyTFD (new Google APIs project setup) ■ goo.gl/KMfbeK (common Python boilerplate code review) ○ GOOGLE APIs ■ goo.gl/ZIgf8k and goo.gl/EySSQV (Google Drive API) ■ goo.gl/pFYUQ2 (Gmail API) ■ goo.gl/KuYMiq (Google Calendar API) ■ goo.gl/N1RPwC and goo.gl/U6Oljn (Google Sheets API) ■ goo.gl/o6EFwk (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 ■ developers.google.com/apps-script ○ Video resources ■ goo.gl/1sXeuD (Apps Script intro) ■ goo.gl/oAzBN9 (Google Maps & Gmail APIs) ■ goo.gl/YuwZ0E (YouTube [Data] API) ■ goo.gl/xSzGl4 (Google Forms) Alternative 2 ● What about my favorite HTTP request library? ○ requests ■ python-requests.org ○ So can I use 'requests' to talk to Google APIs? ○ Answer: YES, but... ■ Not many examples out there ■ I found one at gist.github.com/ymotongpoo/1907281 ■ 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 ■ developers.google.com/adwords/api/docs/clientlibraries ○ Google Maps (Web Services) ■ developers.google.com/maps/web-services/client-library ○ Google Cloud Platform ■ cloud.google.com/python/apis ○ Firebase platform (Android, iOS, Web, C++, Node.js, Java) ■ firebase.google.com/docs/libraries Thank you! Questions? +Wesley Chun google.com/+WesleyChun @wescpy twitter.com/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: goo.gl/Rq6ABI 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 goo.gl 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 ○ Script.google.com ○ 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 goo.gl/1sXeuD
  31. 31. JS
  32. 32. JS
  33. 33. JS Spreadsheet with code goo.gl/SVxoCt
  34. 34. Confidential & Proprietary Reference + next steps ● Developer videos and/or blogposts ○ goo.gl/1sXeuD (Apps Script intro) ○ goo.gl/oAzBN9 (Google Maps & Gmail APIs) ○ goo.gl/nKfBQi (YouTube [Data] API) ○ goo.gl/EK5edG (Google Forms) ● Documentation ○ developers.google.com/apps-script ● Need help? ○ stackoverflow.com/questions/tagged/google-apps-script ● Community ○ plus.google.com/communities/102471985047225101769 Thank you! Questions? +Wesley Chun google.com/+WesleyChun @wescpy twitter.com/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 google.com/+WesleyChun @wescpy twitter.com/wescpy slide deck goo.gl/TGCm8q

×