exploring google apis with python & javascript
TRANSCRIPT
Confidential & ProprietaryConfidential & Proprietary
Exploring Google APIswith Python & JavaScript
+Wesley Chun, @wescpyDeveloper Advocate
Silicon Valley CodeCampOct 2015: San José, CA
GDG New York CityNov 2016: New York, NY
Contribute questions at:
goo.gl/Rq6ABI
I teach
I write
I code
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)
PyConMay 2016: Portland, OR
BayPIGgiesAug 2016: Mountain View, CA
Exploring Google APIswith Python
+Wesley Chun, @wescpyDeveloper Advocate
Can't wait? pip{,3} install -U google-api-python-clientAND console.developers.google.com
SF Python project nightOct 2016: San Francisco, CA
GDG NYCNov 2016: New York, NY
Contribute questions at:
goo.gl/Rq6ABI
Outline
●Overview● Getting started● Python● Live demo(?)● Wrap-up
Part I: Google APIs overview
BUT... wait, there’s more...
Part II: Getting Started with Google APIs
Developers Console (devconsole)
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"
Part III: Using Google APIs with Python
developers.google.com/discovery/libraries
Open source client libraries for many
languages, not just
SIMPLE
AUTHORIZED
API access
Simple API access
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
SIMPLE
AUTHORIZED
Which do you choose?
Part IV: Demo (live would make it interesting)
Searching Google+ for social posts
Searching YouTube for videos
Listing your files in Google Drive
Use of multiple APIs supportedSimple, authorized, or a mix of both types of APIs; re-uses HTTP client; also see goo.gl/cdm3kZ
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)
Check out our Node.js Markdown-to-Google Slides sample app demoing the Slides API
github.com/googlesamples/md2googleslides (JS)
Part V: Wrap-up
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)
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
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 Chungoogle.com/+WesleyChun
@wescpytwitter.com/wescpy
Google Apps ScriptAccessing G Suite & other Google services with JavaScript
+Wesley Chun, @wescpyDeveloper Advocate
Silicon Valley CodeCampOct 2015: San José, CA
GDG New York CityNov 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
Another Google secret?
+JavaScript-API “flavor”+built-in “flavor”-OAuth2 (you)
JS
Not your daddy’s JavaScript
Not Node.js either
!=
Drive
Apps just the beginning
Drive
Apps Script powers add-ons
Other Google services
But wait, there’s more...Google Apps services
Admin SDKCalendarContactsDocsDriveFormsGmailGoogle+ DomainsGroupsMapsSitesSheetsTasks
Other Google servicesAdSenseAnalyticsBigQueryFusion Tablesgoo.glMirror (Glass)PredictionTranslateYouTube
Other servicesURL FetchJDBC… and more…
Drive
Teachers’ tools
Drive
Automation (i.e., mail merge)
Drive
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
Your first Apps Script project
OAuth2 flow
“Hello World”
Apps Script intro videogoo.gl/1sXeuD
JS
JS
JS
Spreadsheet with codegoo.gl/SVxoCt
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 Chungoogle.com/+WesleyChun
@wescpytwitter.com/wescpy
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 Chungoogle.com/+WesleyChun
@wescpytwitter.com/wescpy
slide deckgoo.gl/TGCm8q