Presented on 22 September 2016.
This is a technical presentation that provides an introduction to the Google's APIs for (Google Analytics, Drive, and Sheets) APIs and how they can be combined with ORCID API and other external sources. More Specifically, we talk about
- Accessing Google APIs with a service account
- Querying the Google Analytics Core Reporting API
- Creating/managing files with Google Drive and Sheets APIs
- Integrating data from externals sources using the ORCID public API
Presenter: Liz Krznarich from ORCID
Liz is a software developer and UI designer at ORCID, where she takes on projects ranging from server automation to user interface design, and development for content management systems. Liz has a range of experience in design, web development, technology training and academic libraries, and previously worked at the University of Wisconsin. Liz earned a BS in Graphic Design and a Master's in Library & Information Science from the University of Wisconsin.
2. orcid.org support@orcid.org
API EXTRAVAGANZA
Reporting. Analytics. Metrics.
Whatever you choose to call it,
we all want to know more about
the impact of our work.
Who’s using
my
datasets?
How does my
work connect
to others’?
Who’s
visiting my
repository?!
4. orcid.org support@orcid.org
API EXTRAVAGANZA
…but to get a complete picture,
you may need to combine data
from multiple tools
APIs to the rescue!
5. orcid.org support@orcid.org
API EXTRAVAGANZA
Today’s topics
Custom reporting with Google
Analytics / Drive / Sheets APIs +
ORCID APIs
6. orcid.org support@orcid.org
API EXTRAVAGANZA
In this walk-through we’ll:
1. Query the Analytics API
2. Set up Google API credentials
3. Get Analytics data & upload to
Drive
4. Set up ORCID API credentials
5. Get data from ORCID & add it to
our Drive file (using the Sheets
8. orcid.org support@orcid.org
API EXTRAVAGANZA
Pre-reqs: Get a Google Analytics
account, create a new project & set up
tracking
https://analytics.google.com
12. orcid.org support@orcid.org
API EXTRAVAGANZA
Dimension & metrics & filters, oh
my!
• Dimensions: How to break down the data (city,
device)
• Metrics: What you’re counting (clicks, views, etc)
• Filters: Limit data by specific criteria
Analytics API
Reference:https://developers.google.com/analytics/devguides/repo
rting/core/v3/reference
Dimensions & Metrics Reference:
https://developers.google.com/analytics/devguides/reporting/core/
18. orcid.org support@orcid.org
API EXTRAVAGANZA
Add Service Account to
Analyticshttps://analytics.google.com/analyt
ics/web/#management/Settings > User
Management
Guess what?! If you’re using the DSpace Google Analytics module,
you’ve already done steps 4-8, and you can use the same service
account credentials for your custom applications!
19. orcid.org support@orcid.org
API EXTRAVAGANZA
Create a new Drive folder & share it
with Service Account
https://drive.google.com/drive/my-drive
21. orcid.org support@orcid.org
API EXTRAVAGANZA
3. Get Analytics data & upload to
Drive
• Import Google oauth2client & apiclient
libraries
• Authenticate to Analytics, Drive & Sheets
APIs
• Get Analytics data
• Upload Analytics data to Drive
22. orcid.org support@orcid.org
API EXTRAVAGANZA
Authenticate to Analytics, Drive &
Sheets APIs (Aaargh!!!)
(via Oauth2
SignedJwtAssertionCredentials)
You could read this:
https://developers.google.com/identity/protoc
ols/OAuth2ServiceAccount#authorizingreque
sts
Or just borrow someone else’s code.
23. orcid.org support@orcid.org
API EXTRAVAGANZA
Get Analytics Data
https://developers.google.com/analytics/devg
uides/reporting/core/v3/coreDevguide
Finally something
simple!
Import a client library
and let ‘er rip!
24. orcid.org support@orcid.org
Upload data to Drive
https://developers.google.com/drive/v3/refere
nce/files/create
API EXTRAVAGANZA
Tip: Start with an
existing Drive
folder that your
Service Account
already has
access to
26. orcid.org support@orcid.org
ORCID Public vs Member APIs
API EXTRAVAGANZA
API Type Access Features
Public Freely available (ORCID iD
required)
• Get authenticated ORCID iDs
from users
Search/retrieve public data
Member Available to ORCID member
organizations (sandbox test
environment freely available)
All Public API features, plus:
• Search/retrieve "limited-access"
data
• Add to/update ORCID records
• Register webhooks
Premium members only
32. orcid.org support@orcid.org
Get data from ORCID
In the example code, we use HTTP requests (via
PyCurl) to get an access token and loop through a
list of DOIs, checking to see which are linked to
ORCID iDs
API EXTRAVAGANZA
33. orcid.org support@orcid.org
First, we need an access token
Valid for 20yrs – can be used for multiple searches
API EXTRAVAGANZA
You’ll need your client
ID & secret here!
34. orcid.org support@orcid.org
Then, use the token to send queries
Solr query syntax - see
https://members.orcid.org/api/tutorial-searching-data-
using-api
API EXTRAVAGANZA
curl -H "Content-Type: application/orcid+xml" -H
"Authorization: Bearer 5d0c7545-f59f-44c5-bcde-
f83438beb3ef"
"https://pub.sandbox.orcid.org/v1.2/search/orcid-
bio/?defType=edismax&q=digital-object-
ids:%2210.1087/20120404%22" That token you generated
goes in here!
35. orcid.org support@orcid.org
Edit the new sheet to add your data
https://developers.google.com/sheets
http://gspread.readthedocs.io
• Python gspread library makes life easy
• Sheets API v3 w/out a 3rd party library =
frightening; v4 looks friendlier
API EXTRAVAGANZA
36. orcid.org support@orcid.org
Edit the new sheet to add your data
1. Get the Drive file id
2. Open the file
3. Figure out which cells
to edit & send the
update request
API EXTRAVAGANZA
37. orcid.org support@orcid.org
Now, take that data and do cool stuff!
(like charts with Google Charts API)
https://developers.google.com/chart
API EXTRAVAGANZA
38. orcid.org support@orcid.org
Hot Tips!
• Tokens expire in 1hr (no refresh
token…just get a new one)
• Analytics API is twitchy – expect sporadic
errors when running lots of queries
• Sheets API is slooooow – try to combine
as many actions as possible into 1 request
API EXTRAVAGANZA
39. orcid.org support@orcid.org
Get the code
Demo site
http://orcid.github.io/analytics-demo
Code
https://github.com/lizkrznarich/orcid-
demo/analytics