42
Confidential & 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

Exploring Google APIs with Python & JavaScript

Embed Size (px)

Citation preview

Page 1: Exploring Google APIs with Python & JavaScript

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

Page 2: Exploring Google APIs with Python & JavaScript

I write

I code

Page 3: Exploring Google APIs with Python & JavaScript

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)

Page 4: Exploring Google APIs with Python & JavaScript

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

Page 5: Exploring Google APIs with Python & JavaScript

Part I: Google APIs overview

Page 6: Exploring Google APIs with Python & JavaScript

BUT... wait, there’s more...

Page 7: Exploring Google APIs with Python & JavaScript
Page 8: Exploring Google APIs with Python & JavaScript

Part II: Getting Started with Google APIs

Developers Console (devconsole)

Page 9: Exploring Google APIs with Python & JavaScript
Page 10: Exploring Google APIs with Python & JavaScript
Page 11: Exploring Google APIs with Python & JavaScript
Page 12: Exploring Google APIs with Python & JavaScript
Page 13: Exploring Google APIs with Python & JavaScript

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"

Page 14: Exploring Google APIs with Python & JavaScript
Page 15: Exploring Google APIs with Python & JavaScript
Page 16: Exploring Google APIs with Python & JavaScript

Part III: Using Google APIs with Python

developers.google.com/discovery/libraries

Open source client libraries for many

languages, not just

Page 17: Exploring Google APIs with Python & JavaScript

SIMPLE

AUTHORIZED

API access

Simple API access

Page 18: Exploring Google APIs with Python & JavaScript

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

Page 19: Exploring Google APIs with Python & JavaScript

SIMPLE

AUTHORIZED

Which do you choose?

Part IV: Demo (live would make it interesting)

Page 20: Exploring Google APIs with Python & JavaScript

Searching Google+ for social posts

Searching YouTube for videos

Page 21: Exploring Google APIs with Python & JavaScript

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

Page 22: Exploring Google APIs with Python & JavaScript

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)

Page 23: Exploring Google APIs with Python & JavaScript

Check out our Node.js Markdown-to-Google Slides sample app demoing the Slides API

github.com/googlesamples/md2googleslides (JS)

Page 24: Exploring Google APIs with Python & JavaScript

Part V: Wrap-up

Page 25: Exploring Google APIs with Python & JavaScript

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)

Page 26: Exploring Google APIs with Python & JavaScript

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

Page 27: Exploring Google APIs with Python & JavaScript

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

Page 28: Exploring Google APIs with Python & JavaScript

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

Page 29: Exploring Google APIs with Python & JavaScript

Another Google secret?

+JavaScript-API “flavor”+built-in “flavor”-OAuth2 (you)

Page 30: Exploring Google APIs with Python & JavaScript

JS

Not your daddy’s JavaScript

Page 31: Exploring Google APIs with Python & JavaScript

Not Node.js either

!=

Page 32: Exploring Google APIs with Python & JavaScript

Drive

Apps just the beginning

Drive

Apps Script powers add-ons

Page 33: Exploring Google APIs with Python & JavaScript

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…

Page 34: Exploring Google APIs with Python & JavaScript

Drive

Teachers’ tools

Drive

Automation (i.e., mail merge)

Page 35: Exploring Google APIs with Python & JavaScript

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

Page 36: Exploring Google APIs with Python & JavaScript

Your first Apps Script project

Page 37: Exploring Google APIs with Python & JavaScript

OAuth2 flow

“Hello World”

Apps Script intro videogoo.gl/1sXeuD

Page 38: Exploring Google APIs with Python & JavaScript

JS

Page 39: Exploring Google APIs with Python & JavaScript

JS

Page 40: Exploring Google APIs with Python & JavaScript

JS

Spreadsheet with codegoo.gl/SVxoCt

Page 41: Exploring Google APIs with Python & JavaScript

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

Page 42: Exploring Google APIs with Python & JavaScript

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