0

I've tried to make script that searches image on internet using GoogleImages, and I used this:

const GoogleImages = require('google-images');
const gse = new GoogleImages('my_cse_id','my_api_key');
const search_query = args.join(" ");
var image;
gse.search(search_query)
.then(images => {
    image = images[0].url
})

But i just get an error:

Uncaught ErrorClass
VuzZ
  • 13
  • 1
  • 3
  • Hi VuzZ and welcome to SO. Could you tell more about *where* the error occurs and what line causes it? Also, you're using async code `gse.search().then()` which probably won't work as you expect it to, assuming you want to use the `image` variable in a later stadium. See [this thread](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) which explains how you should use it. – Emiel Zuurbier Jan 24 '22 at 15:16
  • Please add that to the question, for as you might have noticed, the comments don't read easily and this is something that is meant for everyone to see. **But omit the API key! Someone here could use your key.** Though your error is a HTTP error. The 403 error means that you're not allowed to make this request. This usually happens whenever your credentials aren't properly set or you simply lack the correct authorization to make this request. – Emiel Zuurbier Jan 24 '22 at 19:45

0 Answers0