HK420
September 22, 2020, 2:05pm
1
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?
HK420
September 22, 2020, 3:19pm
3
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.
HK420
September 22, 2020, 3:21pm
5
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:
HK420
September 22, 2020, 3:25pm
7
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:
You need an API key, you should also be using the NPM package.
HK420
September 22, 2020, 3:48pm
11
I have an API key, how would I put it in the url?
HK420
September 22, 2020, 3:49pm
12
Just testing out the endpoint before using the NPM module
Try using the oauth parameter.
HK420
September 22, 2020, 3:51pm
14
What? I don’t understand lmao.
Usage: Creating an Instance
1 Like
Please take some time to read the documentation.
HK420
September 22, 2020, 4:00pm
17
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
HK420
September 22, 2020, 4:17pm
19
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.