Getting tags from Google's Cloud Vision API
Similar to getting the sizes of the images, we will gather the
tags using another program which we run on the server using Node.
For every filename, it should construct the URL, contact the
Google Cloud Vision API and retrieve a
landmark tag and a collection of
label tags.
- I suggest you develop your program using
better6whs.json
rather than the entire database.
- Enable the Cloud Vision API, following
their instructions.
- Look at the How-to-Guides on the menu on the left on the page for the Cloud Vision API.
In "Authenticate", the relevant part is "API Key". In "Make a Request", we
provide the image
as a publicly-accessible URL, that is, the third option.
We'll be using "Detect Labels", and, under
"Detect Other Features", Landmarks.
- Please access the API using a Node request object, rather than
requiring Google's client library; it's useful for any API so it's a
better skill to have, and it's no more difficult. It's very similar
to the xmlHTTPrequst object used by browser code.
Here is an example of doing an API
call to the Cloud Vision API using Node's request object.
Try it!
-
In the callback function of the API request,
you'll need to add the new data to the database,
using the SQL UPDATE
command.
If there is a landmark tag, put it into the landmark column.
Put at most the top six of the labes into the
"tags" column, as a comma-separated list.