首页 > 解决方案 > 如何使用 Yelp API 获取业务 ID 数组的数据?

问题描述

我有一个包含企业 ID 的长数组,我想获取与该 ID 关联的每个业务数据。

尽管使用 axios 和正确的标头给了我结果,但由于以下错误/异常,我仍然会丢失一些数据:TOO_Many_Requests_Per_Second.

我用于获取数据的代码如下:

const headers = {
        Authorization: 'Bearer <token>',
        'Content-Type': 'application/json',
      };
 data.maps(async (product : any) => {
        const res = await axios.get(`${URLS.FETCH_BUSINESS_DETAILS}/${product.businessId}`, { headers      });
      });

标签: javascriptaxiosyelp

解决方案


Yelp API 的开发人员文档包含有关此错误响应的以下信息:

每秒查询 (QPS) 速率限制

QPS 限制

如果您对 API 进行查询过快,您可能会收到带有 json 正文的 HTTP 429 错误:

{
    "error": {
        "code": "TOO_MANY_REQUESTS_PER_SECOND",
        "description": "You have exceeded the queries-per-second limit for this endpoint.
                        Try reducing the rate at which you make queries."
    }
}

如果您经常看到这些,请放慢调用 API 的速度。


推荐阅读