API BaseJump: Image Search Abstraction Layer
User Stories:
- I can get the image URLs, alt text and page urls for a set of images relating to a given search string.
- I can paginate through the responses by adding a ?offset=2 parameter to the URL.
- I can get a list of the most recently submitted search strings.
Example Usage:
Search for 'keyword' (10 at a time):
http://localhost:3000/api/imagesearch/lolcats
View 2nd page of results:
http://localhost:3000/api/imagesearch/lolcats&offset=10
Search for 'multiple keywords':
http://localhost:3000/api/imagesearch/lolcats funny&offset=10
View history of the latest 10 submitted searches:
http://localhost:3000/api/latest/imageseach
Google CSE Instructions
Based on instructions from: https://github.com/vadimdemedes/google-images and this documentation: https://developers.google.com/custom-search/json-api/v1/overview
NOTE: only accepts 100 searches per day. Can purchase additional searches for $5/1000 queries.
- Create a Google Custom Search Engine (https://cse.google.com/cse)
- name the search, but do NOT specify any sites (ie. search entire web, rather than any specific sites).
- under advanced, enable image search.
- under advanced, 'Restrict Pages by Schema.org Types'. Use 'Thing' (ie. root-level, everything) as the limitation.
- get CX ID from this page.
- Set up a Google Custom Search Engine API (https://console.developers.google.com/)
- Create a Credential (API Key).
- check quota usage here: https://code.google.com/apis/console
Google API Explorer Tests
https://developers.google.com/apis-explorer/#p/customsearch/v1/
cURL Tests
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET "https://www.googleapis.com/customsearch/v1?key=ABCabc123ABC_ab1A-A&cx=0123456789:abcdefghij&q=testing+1+2+3+4&num=10&searchType=image&alt=json"
Contents of .env File:
DB_URL='mongodb://localhost:27017/searchdb'
API_KEY='ABCabc123ABC_ab1A-A''
CX='0123456789:abcdefghi'