My own efforts with reddit to learn and use apis

Can someone help me understand what I’ve done wrong on this project? I think I’ve put an appropriate amount of commenting in there. I didn’t want it to get too cray with comments, but I still may have crossed a line.

Your assistance is appreciated!!!

Alright…I just pulled all my hair out trying to figure this one out :joy:

Firstly, you’ve passed in url as an argument, but are not using it in your function… its causing a forbidden error.

Secondly, you cannot do string interpolation in an api call, so you first need to save the interpolated string to a variable, and then pass that variable in. (I hadn’t ever tried to, so I learned something new with this!)

Not sure if you were having other problems, but getting the data to populate is a pretty good start…here’s what I was able to get working:

function getRedditData(term, filter) {
  var link = `https://www.reddit.com/r/${term}/${filter}.json`;
   if(term === '' || filter === '') {
    throw error
  }
 
  fetch(link)
    .then( res => res.json() )
    .then( jsonData => console.log(jsonData))
    .catch( error => console.error('getRedditData Error:', error) );
}

console.log(getRedditData('Hockey','top'))
1 Like

Hi @cndragn! I wanted you to know I really appreciated your feedback. As you were the only one and it took a while I had already modified my code extensively since then, BUT what’s exciting is you made good points that still had value to me and so regardless of the specific impact your efforts were greatly appreciated.

Link to Repo of my current code if you are curious. This is like v0.1 of where I plan to go, but still I wanted to share since you made a big effort and I wanted to reciprocate with some sense of where I have gotten to to this point.

If you like what I’m doing and want to contribute go for it; always happy to practice working with someone else.

Again thank you very much and all the best in the new year!!

1 Like

Thank you for updating!!! Thats awesome you were able to figure things out, also great to hear that I still helped in some way :smiley: I will def check out your app asap…interested to see!