I came across Google’s FactCheckTools API today, so I thought it might be fun to add to my bmApiCentral Apps Script library. This API can be used to both search popular fake news claims and to post fact check reviews. In this case though, I’ve only implemented the search piece in Apps Script, which is the subject of this article.
Getting started
As usual there’s a few things to do before getting started
Libraries
You’ll need a couple of my libraries.
bmApiCentral – 1L4pGblikbjQLQp8nQCdmCfyCxmF3MIShzsK8yy_mJ9_2YMdanXQA75vI github
bmPreFiddler – 13JUFGY18RHfjjuKmIRRfvmGlCYrEkEtN6uUm-iLUcxOUFRJD-WBX-tkR github
Cloud Project
You’ll also need to use a regular cloud project and replace the default project in your Apps Script settings. I won’t go into the details of all that here, as if you’re reading this, you probably already know how to do all that. That cloud project will need this API enabled
- Fact Check Tools API
Api keys
For this API you need an ApiKey. You can create this via the API credentials section of the Cloud Console. Add this as a script property called “apiKey” in your project settings.
Exports
All my projects feature an Exports Script nowadays, which is used to manage libraries, check the validity of access to methods and properties, and deal with any declaration order issues. You can copy and paste this one as is into a script file in your project.
Dependencies
The api library is dependendency free, so you need to register your UrlFetch app. Unusually, the Fact check API does not need any Oauth token (in fact supplying one would make it fail), so the only dependency required is below.
Fact check example
Now we can do a trial fact check – here’s the code to return a single item.
Response
{ text: 'The body of a homeless man found in San Diego has been identified as that of Elvis Presley.',
claimReview:
[ { publisher: [Object],
url: 'https://www.snopes.com/fact-check/elvis-presley-body-elderly-homeless-man/',
title: 'Was the Body of an Elderly Homeless Man Identified as Elvis Presley?',
reviewDate: '2015-01-31T16:00:00Z',
textualRating: 'False',
languageCode: 'en' } ] }
Spreadsheet example
Let’s do a little more now and use the API to populate a sheet which has series of claims that need fact checked.
Let’s try these
claim |
the earth is flat |
Covid is a hoax |
The moon landings were faked |
Elvis is alive |
Loch ness monster exists |
alien abductions |
near death experiences |
As usual,we’ll use my bmPreFiddler library to deal with talking to the sheets. Here’s the code. You’ll also find it in the testFact project – link at the end of this article.
Pagination with ApiCentral
By default, pagination is handled automatically and you’ll get back all the matching results, irrespective of the pageSize limits on the API. You can limit how many results are returns with the limit parameter- for example:
Note also that bmApiCentral has caching built in by default.
Example results
Here’s the result of fact checking our original queries with a limit of 5 results per query.
Links
bmApiCentral – 1L4pGblikbjQLQp8nQCdmCfyCxmF3MIShzsK8yy_mJ9_2YMdanXQA75vI github
bmPreFiddler – 13JUFGY18RHfjjuKmIRRfvmGlCYrEkEtN6uUm-iLUcxOUFRJD-WBX-tkR github
testFact – Take a copy of the example code in this article github
bmPreFiddler – Take a copy of the test sheet