1

我是时钟 API 集成的新手。我想检索所有工作区。我正在请求“ https://api.clockify.me/api/workspaces/ ”这个 API 并在标题中发送“X-Api-Key”。当我向邮递员请求此 API 时,我得到(成功响应)所有数据作为响应。但是当我从浏览器请求这个 API 时,我得到 '{"message": "Full authentication is required to access this resource", "code":1000}' 这个错误响应。我不明白有什么问题。

卷曲请求:

curl 'https://api.clockify.me/api/workspaces/' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Referer: http://localhost:4200/' \
-H 'Origin: http://localhost:4200' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36' \
-H 'X-Api-Key: {API-Key}' --compressed

请帮忙。先感谢您。

4

1 回答 1

0

发生此错误是因为您的 Referer 是 localhost -H 'Referer: http://localhost:4200/'并且clockify API不支持localhost请求。

如果您必须在本地主机中运行 clockify API 以执行此步骤:

  1. 设置Virtual Host locally我已经使用XAMPP,所以我可以附加虚拟主机设置本地链接: https ://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in- ubuntu

  2. 使用ng build命令构建您的项目

  3. 然后hosts使用此命令配置您的项目sudo gedit /etc/hosts
  4. /opt/lampp/etc/extra/httpd-vhosts.conf然后在文件中设置您的目录路径

之后,您可以使用clockify API locally

我希望你能正确理解我在这里解释的内容

于 2019-02-21T11:03:10.410 回答