How to solve google books api 403 restriction?

I’m trying to collect about 40 books from the google api. This is the code

const title = ["0596007124","0704381362", ...]
title.forEach(isbn=>{
  url = "https://www.googleapis.com/books/v1/volumes?q=isbn:"  + isbn; 
  promise.push(axios.get(url))
})

It works sometimes if I only loop through 3 books. But I have been able to get all of them at one point.

From searching it seems that using this line somewhere would do the trick

content: `script-src 'self' ${url} 'unsafe-inline' 'unsafe-eval'`

But I don’t know how to use it. I tried to put it with the get method

axios.get(url,{
content: `script-src 'self' ${url} 'unsafe-inline' 'unsafe-eval'`
})

But didn’t work.

So what is the exact error response? It actually sounds more like you exceeded your request rate limit, in which case you might increase the per-user quota (requires an account, obviously). However 40 individual requests is quite a lot anyway, so I’d suggest to query these books in a single request instead:

const isbns = ['0596007124', '0704381362']

const url = isbns.reduce(
  (res, isbn, index) => res + (index > 0 ? '+OR+' : '') + 'isbn:' + isbn,
  'https://www.googleapis.com/books/v1/volumes?q='
)

axios.get(url).then(console.log)

Oh I love it. I didn’t know that could be done.

Thanks so, much it works

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.