In this tutorial, I will show you how to create a custom google search engine to search large images.
You can customize this engine if you want.
The first step is to set the YOUR_API_KEY using the webpages from the commented source code:
In the next one, you need to set the YOUR_SEARCH_ENGINE_ID using the webpages from the commented source code:
Open a new google apps script in the online editor and add this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | function search_custom_engine() { // Use your YOUR_API_KEY and YOUR_SEARCH_ENGINE_ID with your API key and search engine ID // YOUR_API_KEY, you can use the <strong>Get a Key</strong> button from https://developers.google.com/custom-search/v1/introduction // YOUR_API_KEY is set by your google project // YOUR_SEARCH_ENGINE_ID from https://programmablesearchengine.google.com/controlpanel/create var API_KEY = ''; var SEARCH_ENGINE_ID = ''; // the search query and the size parameter to retrieve large images var query = 'christmas'; var size = 'large'; // Make an HTTP GET request to the Google Custom Search API var response = UrlFetchApp.fetch( 'https://www.googleapis.com/customsearch/v1?' + 'key=' + API_KEY + '&cx=' + SEARCH_ENGINE_ID + '&q=' + query + '&imgSize=' + size + '&searchType=image' ); // Parse the JSON response var json = JSON.parse(response.getContentText()); // this create an empty list to store the image URLs var imageUrls = []; // Iterate through the search results and add the image URLs to the list for (var i = 0; i < json.items.length; i++) { imageUrls.push(json.items[i].link); } // Print the list of image URLs Logger.log(imageUrls); } |
The result of this running source code is this:
1 | [https://www.history.com/.image/c_fit%2Ccs_srgb%2Cfl_progressive%2Cq_auto:good%2Cw_620/MTY4ODE4ODA4MzY1MDAwNDY1/christmas-gettyimages-184652817.jpg, https://images.thdstatic.com/productImages/851f5f49-7285-43b6-ba72-41dbfc7910c4/svn/home-accents-holiday-pre-lit-christmas-trees-tg76m3acdl19-e1_600.jpg, https://www.history.com/.image/c_fill%2Ccs_srgb%2Cfl_progressive%2Ch_400%2Cq_auto:good%2Cw_620/MTY4OTA4MzI0ODc4NjkwMDAw/christmas-tree-gettyimages-1072744106.jpg, https://images.thdstatic.com/productImages/10100084-e200-499a-abd0-bfb8c261b751/svn/home-decorators-collection-pre-lit-christmas-trees-22le31014-e1_600.jpg, https://www.history.com/.image/ar_16:9%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cg_faces:center%2Cq_auto:good%2Cw_620/MTY4ODE4ODA4MzY1MDAwNDY1/christmas-gettyimages-184652817.jpg, https://assets.simpleviewinc.com/simpleview/image/fetch/c_fill,h_396,q_75,w_704/https://assets.simpleviewinc.com/simpleview/image/upload/crm/gatlinburgtn/DSC05698_11CE4BF4-5056-A36F-23D4834C3526E5E9_11d4c0f5-5056-a36f-23a25a7a9b2281a2.jpg, https://www.history.com/.image/ar_16:9%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cg_faces:center%2Cq_auto:good%2Cw_768/MTY4OTA4MzI0ODc4NzU1NTM2/christmas-trees-gettyimages-1072744106.jpg, https://img.freepik.com/free-psd/transparent-christmas-background-with-realistic-red-baubles_1393-392.jpg, https://www.history.com/.image/c_fill%2Ccs_srgb%2Cfl_progressive%2Ch_400%2Cq_auto:good%2Cw_620/MTY4ODE4ODA4MzY1MDAwNDY1/christmas-gettyimages-184652817.jpg, https://img.freepik.com/free-vector/gradient-christmas-frames-borders-collection_52683-76118.jpg] |