Introducing the (new) Google Docs API (2019)

wescpy 174 views 8 slides Apr 26, 2019
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

This is a 15-20 minute talk introducing developers to the (new as of Feb 2019) Google Docs API. The example demonstrated is a "mail merge" app, and whose data comes from a Google Sheet. Bonus: attendees get an intro to using the Sheets API too.


Slide Content

2018 | Confidential and Proprietary
I,YN2d^c, Ye M,er [
G22&e D2cR API
Wesley Chun (@wescpy)
Developer Advocate, Google Cloud
G S^Ye Deq S2r
goo.gl/JpBQ40
Ab2^Y Ye RKea#eN
●Developer Advocate, Google Cloud
●MRR2, 7 e,ab&e c^NNe,Y a,d ^Y^Ne deqe&2KeNR Y2 be R^cceRR^& ^R,
G22&e C&2^d a,d 2YeN G22&e deqe&2KeN Y22&R 6 APIR 6 a,d K&a?2N+R
●Vde2R 7 2RY 2 Ye G S^Ye Deq S2r 2, Y2^T^be
●B&2R 7 deqe&2KeNR 522&eb&2 5c2+ A R^Ye fdeqe&2KeNR 522&eb&2 5c2+
●Tr?eNR 7 AreRcKx 6 AG22&eDeqR 6 AGS^YeDeqR
●Bac#N2^,d
●S2?raNe e,,eeN A aNcYecY 2N ?? ? xeaNR
●O,e 2 Ye 2N,a& Ya22 :Ma& e,,eeNR
●Author 2 beRYRe&&, yC2Ne PxY2, y b22#R Mc2NeKxY2, 5c2+ [
●TeaceN a,d Yec,ca& ,RYN^cY2N R,ce ????
●Fe&&2r 2 Ye PxY2, S2?raNe F2^,daY2,

G S^Ye APIR

Google APIs client
libraries; demos in
OYeNR 7
developers.google.com/
api-client-library
PxY2, ? 2N ? 7
pip{3,} install -U
google-api-python-client
A^Y2N?ed API acceRR
OAuth boilerplate
goo.gl/KMfbeK

OA^Y? 2N
API #ex
HTTP fbaRed REST APIR
?
HTTP
?
G22&e APIR NeM^eRY fNeRK2,Re r2N#?2r
●AKK&caY2, +a#eR NeM^eRY
●ReM^eRY Neceqed bx ReNqce
●PN2ceRR daYa 6 NeY^N, NeRK2,Re
●ReR^&YR Re,Y Y2 aKK&caY2,
MYxKca& c&e,Y fReNqeN +2de& [
G S^Ye 7 G22&e D2cR
Docs API gives you access to read &
write documents programmatically so
you can autogenerate them with data
integrated from various sources
developers.google.com/docs

Ma& +eNe
Ma& +eNe

Ma& +eNe
Ma& +eNe MYe+K&aYe &2ba& ReaNc A NeK&ace [
requests = [
# (global) search-and-replace text
{'replaceAllText': {
'containsText': {'text': '{{TITLE}}'},
'replaceText': 'Hello World!',
}},
]
DOCS.documents().batchUpdate(body={'requests': requests},
documentId=DOC_ID, fields='').execute()
Mail merge
bit.ly/2W1xhNa
(video TBD)

G S^Ye 7 G22&e SeeYR
Sheets API gives you programmatic
access to spreadsheets; has ability
to perform almost any action you
can do from the web interface
developers.google.com/sheets
Try our Node.js customized reporting tool codelab:
g.co/codelabs/sheets
Wx ^Re Ye SeeYR API G
daYa qR^a&?aY2,
c^RY2+?ed NeK2?R
SeeYR aR a daYa R2^Nce

MNaYe SQL daYa Y2 a SeeY
# read SQL data then create new spreadsheet & add rows into it
FIELDS = ('ID', 'Customer Name', 'Product Code',
'Units Ordered', 'Unit Price', 'Status')
cxn = sqlite3.connect('db.sqlite')
cur = cxn.cursor()
rows = cur.execute('SELECT * FROM orders' ).fetchall()
cxn.close()
rows.insert(0, FIELDS)
DATA = {'properties': {'title': 'Customer orders'}}
SHEET_ID = SHEETS.spreadsheets().create(body=DATA,
fields='spreadsheetId').execute().get('spreadsheetId')
SHEETS.spreadsheets().values().update(spreadsheetId=SHEET_ID, range='A1',
body={'values': rows}, valueInputOption='RAW').execute()
Migrate SQL data
to Sheets
goo.gl/N1RPwC
Ta,# x2^ :
WeR&ex C^,
@wescpy