NPM Module to get an image from two different values

Hello, Im trying to find an NPM module that gets a random image from google from two different values.

Imagine I have value 1 which is “Masaki” then value two with the value of “The Lost Village” It would automatically search google for Masaki and The Lost Village and find the most popular image that has both of those tags.

Is there a way I can do this in javascript and get the values from a json file?

If I am correct, Google shut down their search API in 2016. Could you look into another image API?

ofc, I just need to get an image, thats all.

Just do a search! I’m sure there are a ton of services out there.

I’ve tried searching. A lot. Everything I found didn’t work well.

Did you try this? This was the second result when I did a search:

I’ve seen that but it seems pretty complicated ;-; Also, don’t you need an API key?

There is a free plan. Most sites require APIs keys to meter requests.

It looks simple to me. You just have to look at the docs. For example if you want to search for dogs:

https://api.unsplash.com/search/photos?query=dogs

You can also use their NPM package:

image

You need an API key, you should also be using the NPM package.

I have an API key, how would I put it in the url?

Just testing out the endpoint before using the NPM module

Try using the oauth parameter.

What? I don’t understand lmao.

Usage: Creating an Instance

1 Like

Please take some time to read the documentation.

Trying to do

const APP_ACCESS_KEY = 'owo'
const APP_SECRET= 'uwu'

import Unsplash from 'unsplash-js';

const unsplash = new Unsplash({
  applicationId: APP_ACCESS_KEY,
  secret: APP_SECRET
});

unsplash.search.photos("cats", 1)
  .then(toJson)
  .then(json => {
    console.log(json)
  });

but it doesn’t seem to be working…

SyntaxError: Cannot use import statement outside a module

Instead of

import Unsplash from 'unsplash-js';

try

const Unsplash = require('unsplash-js');
1 Like

Tried that aswell with an error of:

TypeError: Unsplash is not a constructor

Try placing the import statement at the very top of your code.