[英]Google Books API Rate Limit Exceeded
通過此演示,我從 Google Books API 中獲得了超出速率限制:
https://angular-temp-slice-demo.stackblitz.io/books
要查看它,請在 chrome 中打開開發者控制台,然后進行一些搜索。 速率限制錯誤將顯示在控制台中。
[],"lazyUpdate":null},"status":403,"statusText":"OK","url":"https://www.googleapis.com/books/v1/volumes?q=test","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://www.googleapis.com/books/v1/volumes?q=test: 403 OK","error":{"error":{"errors":[{"domain":"usageLimits","reason":"userRateLimitExceededUnreg","message":"User Rate Limit Exceeded. Please sign up","extendedHelp":"https://code.google.com/apis/console"}],"code":403,"message":"User Rate Limit Exceeded. Please sign up"}}}
這是搜索代碼(以及 stackblitz book.service 的鏈接) :
onSearch(query: string) {
this.bookStore.query = query;
this.query$.pipe(
filter(Boolean),
debounceTime(500),
distinctUntilChanged(),
tap(async (query: string) => {
const bo: Observable<Book[]> = this.searchAPI(query);
const books: Book[] = await bo.toPromise();
this.bookStore.reset();
this.bookStore.postA(books);
})
)
.subscribe();
然而這個秋田演示沒有得到這個:
https://akita-books-store.stackblitz.io/#/books/find
任何人都知道是什么導致了超出速率限制的錯誤? 我已將去抖動時間設置為 500 毫秒。
這修復了它:
constructor(private http: HttpClient) {
this.bookStore.observeQuery().pipe(filter(Boolean),
debounceTime(200),
distinctUntilChanged(),
tap(async (query: string) => {
const bo: Observable<Book[]> = this.searchAPI(query);
const books: Book[] = await bo.toPromise();
this.bookStore.reset();
this.bookStore.postA(books);
})
)
.subscribe();
}
在我在onSearch
內部執行上述代碼塊之前,每次觸發onSearch
時都會創建訂閱。 現在onSearch
中唯一的內容是:
onSearch(query: string) {
this.bookStore.query = query;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.