Unknown Google API services

And python scripts to try them

Nicolò Gasparini
CodeX

--

Photo by Pawel, on Unsplash

If you used Google solutions as a developer you’ll often have found yourself using one of their API services, they follow REST protocols and the documentation and references are actually pretty clear. There are so many of them and I believe this is because Google has a developer-centric mentality when developing their products, however, some of them are a little less known than others, I’ll try to give you a quick introduction and examples to use them.

What you’ll need is simply a Google account and a Google Cloud Platform account: Google authentication protocols require you to create a google cloud project. Through that, you can authorize API requests in different ways:

  • with a service account key, for actions performed by non-human users created on the Google Cloud IAM page
  • by building an Oauth2 flow that will create end-user credentials and let us perform operations as if it was the user himself doing them
  • with an API key, a simple encrypted string that identifies a Google Cloud project for quota, billing, and monitoring purposes

For the three services shown below, we’ll only use the latter because the data we will be requesting is publicly available.

PageSpeed Insights API

The name itself says it all, this is one of the simplest APIs, it uses Lighthouse, an open-source tool that helps web developers to analyze their website by providing some useful insight about a website's performance.

A response will include debugging information about the analysis such as the userAgent used and Lighthouse version, and results depending on the category requested, for each of which you’ll find an overall score along with more detailed metrics:

  • for performance: speed-index, interactive score, first-contentful-paint, #render-blocking-resources, #redirects, dom-size…
  • for accessibility: aria attributes, color-contrast, button-names, duplicated ids, language specification, heading tags order, focus-traps…
  • for best practices: https presence, doctype, image-aspect-ratio, image responsiveness, errors-in-console, deprecations…
  • for progressive web apps: manifest, icons, url per pages, http redirect…
  • for SEO: presence of metas, robots-txt, canonicals, crawlability…

Fact Check Tools API

This API works around claims, you can create a ClaimReview by specifying what claim you are reviewing, who made it in the first place, and where; after that you can give your rating about the claim, stating sources and a score.
For example, suppose you hear the claim that NASA is involved with chemtrails, you can create a review stating where you found these claims and give your review (eg. False, True, Inaccurate…), with an article on your website to enforce your statement.

Rating on NASA related claim by factcheck.org found on Google’s fact check explorer

For a single user, the most simple use case would just be to query these claims, this can be done using the online explorer or through APIs.
To test this, an API key authorization is sufficient, as the results are publicly available, however, to create ClaimReviews we’ll need to create an OAuth Client ID credential that will authenticate the user creating the claim.

Knowledge Graph Search API

This service lets you query Google’s Knowledge Graph, the “smart” add-on to search results that better understand if what you’re searching is an instance of something well defined instead of just some keywords. This instance could be for example a person, a brand, an institute, or a place. The full list of entity types that can be specified in the request is defined in the schema.org website.

Each result returned in the itemListElement will have a resultScore to indicate the result precision, a type of the possible schema linked above, a name, and a detailedDescription of the entity.

Trump leaving, by Ray on Unsplash

The results of these queries can be unpredictable if additional parameters such as types and prefix are not specified.
For example, the 2nd result for “Armani” is the Armenian language while the 4th result for “Trump” is a Sperm whale.

Google has many more APIs that developers can use to interact with its services, both proprietary and acquired, you can find a full list here.

--

--

Nicolò Gasparini
CodeX
Writer for

Software Engineer and full stack developer 💻 based in Italy — /in/nicologasparini/