I made a request to google books API, trying to retrieve the volumes (a.k.a books) from my bookshelf. But the response I get contains only 10 items whereas on the shelf I have 17 items.
Could this be that my code is faulty, or maybe a restriction from google ? see my code for making the call and for mapping it.
My api.js
import React, { Component } from "react"
import request from 'superagent';
import BookList from './BookList';
class Book extends Component{
constructor(props){
super(props);
this.state = {
books: [],
}
}
componentDidMount(){
request.get("https://www.googleapis.com/books/v1/users/101###############/bookshelves/4/volumes?key=AIzaSyDNMnPGw3################-PecbhU")
.query(null)
.then((data) =>{
console.log(data);
this.setState({books: [...data.body.items]})
})
}
render(){
return(
<div>
<BookList books={this.state.books}/>
</div>
);
}
}
export default Book
And here i map
import React, { Component } from "react"
import BookCard from './bookcard';
const BookList = (props) => {
if(!props){
return null;
}
return(
<div>
{
props && props.books?.map((book, i) => {
return <div >
<BookCard
key={i}
image={book.volumeInfo.imageLinks.thumbnail}
title={book.volumeInfo.title}
author={book.volumeInfo.authors}
url={book.volumeInfo.canonicalVolumeLink}
rating={book.volumeInfo.averageRating}
/>
</div>
})
}
</div>
)
}
export default BookList
CodePudding user response:
As the docs say:
Pagination
You can paginate the volumes list by specifying two values in the parameters for the request:
startIndex - The position in the collection at which to start. The index of the first item is 0.
maxResults - The maximum number of results to return. The default is 10, and the maximum allowable value is 40.
So you can add maxResults=40
to your query to get more results at once.