# Image Search Abstraction - API

**URL:** <https://forum.freecodecamp.org/t/image-search-abstraction-api/35444>\
**Category:** General\
**Created:** [September 9, 2016, 4:37pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444 "2016-09-09T16:37:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jer244](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jer244/32/27050_2.png) [@jer244](https://forum.freecodecamp.org/u/jer244)\
**Post date:** [September 9, 2016, 4:37pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/1 "2016-09-09T16:37:56Z")

</div>

I’m having some trouble finding an API to use for the Image Search Abstraction project.

I’ve already spent hours on this and am pretty frustrated. It seems the major options are google and bing (open to other options, just haven’t been able to find any viable ones).

Google APIs are confusing as hell. Not sure which one to use… I signed up for a key but have no idea how to implement.

Bing looks a lot easier but the service ends in Dec of this year. After that it turns into a paid service on Azure… Do I implement with Bing for the time being and just let it break in Dec?

Any help greatly appreciated.

-Jeremy

---

<div class="post-metadata">

**Author:** ![parmytank](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/parmytank/32/8589_2.png) [@parmytank](https://forum.freecodecamp.org/u/parmytank)\
**Post date:** [September 9, 2016, 4:46pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/2 "2016-09-09T16:46:38Z")

</div>

I used the bing API and found it pretty manageable. I didn’t realize the free service ends in Dec though, that’s too bad. But really, does it matter? Not every project is gonna go on your portfolio; I haven’t looked back at this one since completing it. It’s just for learning.

---

<div class="post-metadata">

**Author:** ![jer244](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jer244/32/27050_2.png) [@jer244](https://forum.freecodecamp.org/u/jer244)\
**Post date:** [September 9, 2016, 4:52pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/3 "2016-09-09T16:52:05Z")

</div>

Thanks for the reply… I completely agree, I was more worried about having to go back and rewrite it if I want the full-stack cert, or even the backend if I haven’t completed it by the time the API is inactivated.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [September 9, 2016, 4:55pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/4 "2016-09-09T16:55:10Z")

</div>

I was unaware of this change to Bing’s TOS…bummer.

If you do end up needing to redo it, you’ll be more experienced by then and probably find Google easier then! Just use Bing for now, it’s pretty easy to work with 🙂

---

<div class="post-metadata">

**Author:** ![jer244](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jer244/32/27050_2.png) [@jer244](https://forum.freecodecamp.org/u/jer244)\
**Post date:** [September 9, 2016, 4:56pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/5 "2016-09-09T16:56:48Z")

</div>

Thanks, I agree, I think that’s my best bet right now.

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [September 29, 2016, 2:13am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/6 "2016-09-29T02:13:53Z")

</div>

I was wondering about this myself. Hunting for a free API to use should **not** be part of the challenge.

I’m trying to use the Google Custom Search API right now, but as near as I can tell it’s complete garbage. After getting a key and fumbling about creating a custom search engine, the results seem to be useless. There is no way I can find to scope the search to images only.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [September 29, 2016, 4:55am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/7 "2016-09-29T04:55:16Z")

</div>

I agree. I didn’t actually know it was expected that I would use an API until I searched Gitter.

It’s a surprising omission, since the Nightlife app instructions specify using the Yelp API. That said, the stock app doesn’t specify an API…seems to be random as to whether or not FCC decides to hold your hand at that point. I would prefer that they suggested an API to use, since the coding presents enough challenges without having to burn several hours researching and testing various APIs.

---

<div class="post-metadata">

**Author:** ![Jon1701](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@Jon1701](https://forum.freecodecamp.org/u/Jon1701)\
**Post date:** [September 29, 2016, 5:08am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/8 "2016-09-29T05:08:01Z")

</div>

I just finished mine, I used the Imgur Gallery Search API. [https://api.imgur.com/endpoints/gallery#gallery-search](https://api.imgur.com/endpoints/gallery#gallery-search)

It’s an alright API, it can either return: (1) link to a gallery with the first image, (2) an image. #2 you can extract thumbnails, but not with #1. There is an endpoint to get thumbnails but that is on a per-image basis.

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [September 29, 2016, 6:09pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/9 "2016-09-29T18:09:39Z")

</div>

Fun times:

> ```
> Your account has been temporarily suspended
> Someone may have used your account --------- to send out a lot of junk messages or
> done something else that violates the Microsoft Services Agreement.
> 
> ```

All my attempts to get an account for this have failed. Hooray. And the text message verification does not work for me. It may be I cannot complete this challenge.

And I’ve never used the account for anything but getting a free subscription to PluralSight for 3 months.

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [September 29, 2016, 6:18pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/10 "2016-09-29T18:18:19Z")

</div>

I may try using this:

> **[pevers/images-scraper](https://github.com/pevers/images-scraper)**
>
> images-scraper - Simple and fast scraper for Google/Bing images using Nightmare and Request

It may not provide all the information the challenge states is required, though.

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [September 30, 2016, 8:27pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/11 "2016-09-30T20:27:34Z")

</div>

The correct API appears to be this:

[https://developers.google.com/custom-search/json-api/v1/reference/cse/list](https://developers.google.com/custom-search/json-api/v1/reference/cse/list)

But you need to create your own “custom” search engine and configure it properly. When you do this, you must ensure “Image search” is enabled. (Off by default). In the actual API call I limited fileType to JPG. This may not be necessary.

The JSON payload will match what the fCC example app produces, so it must be the same API.

Good luck!

---

<div class="post-metadata">

**Author:** ![tbushman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tbushman/32/20238_2.png) [@tbushman](https://forum.freecodecamp.org/u/tbushman)\
**Post date:** [October 8, 2016, 1:23am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/12 "2016-10-08T01:23:30Z")

</div>

Thanks. In addition, I installed npm google-search, and had npm dotenv loaded before defining the keys and cse\_id from my .env file. With that, I’m up and running. Thanks again.

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [October 8, 2016, 2:33am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/13 "2016-10-08T02:33:12Z")

</div>

Fantastic. I’m going to install those now, thanks!

---

<div class="post-metadata">

**Author:** ![tbushman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tbushman/32/20238_2.png) [@tbushman](https://forum.freecodecamp.org/u/tbushman)\
**Post date:** [October 8, 2016, 3:31am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/14 "2016-10-08T03:31:27Z")

</div>

I should specify that I am getting search results, and am now trying to figure out how to extract images from the results, but it felt like a win when I saw that console.log

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [October 8, 2016, 11:33pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/15 "2016-10-08T23:33:58Z")

</div>

Oh, it’s worth noting that if in excitement you try to directly output the whole JSON reply from Google back to the client, you’ll get a circular reference error.

```auto
Error: TypeError: Converting circular structure to JSON

```

Ultimately, you need to pluck a subset of keys from the data Google sends. You can still inspect the data and send it to `console.log` this way if you’re curious:

> <https://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json>

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [October 12, 2016, 3:13am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/16 "2016-10-12T03:13:46Z")

</div>

I can’t emphasize enough the value of using mocking and unit testing when working through the data transformation of the response from Google. It includes much information that is likely not valuable for this challenge and it’s easier to iterate through a solution to extract just what you need if you aren’t constantly hitting the actual API.

For this, I used `axios`, `axios-mock-adapter`, `tape`, and `ramda`. The latter can make the data transformation easier, but it isn’t as popular as other functional libraries so Google is not as useful here. The imperative approach to transforming the data works fine, too.

It seems the `cse_thumbnail` and `cse_image` keys are optional, so be aware!

[https://www.npmjs.com/package/axios-mock-adapter](https://www.npmjs.com/package/axios-mock-adapter)

---

<div class="post-metadata">

**Author:** ![AdventureBear](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/adventurebear/32/74786_2.png) [@AdventureBear](https://forum.freecodecamp.org/u/AdventureBear)\
**Post date:** [November 2, 2016, 11:16pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/17 "2016-11-02T23:16:39Z")

</div>

So how does that work, do you need to hit the Google API once to get a sample of JSOn then hard code that while using axios/mock?

---

<div class="post-metadata">

**Author:** ![jboxman](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jboxman/32/13555_2.png) [@jboxman](https://forum.freecodecamp.org/u/jboxman)\
**Post date:** [November 3, 2016, 1:49am UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/18 "2016-11-03T01:49:22Z")

</div>

Yes, that’s ultimately what I ended up doing.

---

<div class="post-metadata">

**Author:** ![azaraliyev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/azaraliyev/32/163429_2.png) [@azaraliyev](https://forum.freecodecamp.org/u/azaraliyev)\
**Post date:** [February 13, 2017, 2:35pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/19 "2017-02-13T14:35:58Z")

</div>

Hi guys.

Does any of you tried flickr api for this project?

I tried to use it since Bing is gone, and Google’s one is a bit confusing. But on Flickr I can’t seem to figure out how to get links to images. If anyone knows how to get them, please help me out.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:09pm UTC](https://forum.freecodecamp.org/t/image-search-abstraction-api/35444/20 "2021-01-16T13:09:01Z")

</div>

Closed on January 16, 2021, 1:09pm UTC


