unsplash / unsplash-js

🤖 Official JavaScript wrapper for the Unsplash API
https://www.npmjs.com/package/unsplash-js
MIT License
2.15k stars 157 forks source link

No Data in getRandomPhoto #120

Closed LureOfAdventure closed 5 years ago

LureOfAdventure commented 5 years ago

I'm on v6.0.0 and I'm trying to get random photos. Below is how I instantiate the unsplash object and how I query for random photos.

Every time I make a request I get back {"size":0,"timeout":0}

I appreciate any help since I've been stuck on this for quite some time.

Screen Shot 2019-10-23 at 8 20 07 PM Screen Shot 2019-10-23 at 8 25 37 PM
lukechesser commented 5 years ago

@MarkedWarrior I think you need to call json() on the resulting object, because you're getting back an instance from node-fetch. See their docs: https://github.com/bitinn/node-fetch#json

Optionally, we provide a toJson utility function here https://github.com/unsplash/unsplash-js#tojsonres

Note what happens when you do:

unsplash.users.profile('naoufal')
  .then(res => console.log(res));
// => logs an object

unsplash.users.profile('naoufal')
  .then(res => res.json())
  .then(json => console.log(json));
// => logs the actual JSON
LureOfAdventure commented 5 years ago

@lukechesser I can't believe that was the issue... thank you so much for your patience with me.

lukechesser commented 5 years ago

No problem :) It's now documented here so I can point people to it