如何在Wordpress网站上集成第三方API

问题描述:

我需要将第三方API与网站集成在一起,我什至不知道从哪里开始.我只有这个端点-
获取当前人数 https://api.abcfinancial.com/rest/{clubNumber}/clubs/checkins/occupancy currentOccupancy返回俱乐部中的当前成员数. maxOccupancy返回俱乐部中允许的最大成员数. currentOccupancyPercentage返回俱乐部中当前成员的百分比.

I need to integrate a 3rd party API with a website and I have no idea where to even start. I just have this endpoint-
GET Current Occupancy https://api.abcfinancial.com/rest/{clubNumber}/clubs/checkins/occupancy currentOccupancy Returns the current number of members in the club. maxOccupancy Returns the maximum number of members allowed in the club. currentOccupancyPercentage Returns the current percentage of members in the club.

我需要获取当前的占用率并将其显示在滑块旋转幻灯片上.有关如何执行此操作的任何帮助或任何帮助,将不胜感激.

I need to get the current occupancy and show it on the slider revolution slide. Any help of how to do this or anything would be greatly appreciated.

如果您打算专门在前端使用它,则可以使用Javascript实现API调用.在这种情况下,使用 Fetch API即可.您可能希望添加脚本并将其放入functions.php文件中.

If you're looking to use it specifically on the front end, you can look to implement the API call using Javascript. Using the Fetch API would work in that case. You would look to add the script and enqueue it within your functions.php file.

如果需要在服务器端执行此操作,则可以使用 cURL get_file_contents访问API.

If you need to do it on the server side, you can use either cURL or get_file_contents to access the API.

使用服务器端选项时,页面通常将花费更长的时间加载,因为直到服务器点击您的API为止,您都不会返回对站点的响应.使用Javascript选项,您可以在不阻止页面其余部分的情况下访问API.

With the server side option, the page will generally take longer to load as you are not getting back a response to the your site until the server has hit your API. With the Javascript option, you can look to hit the API without blocking the rest of your page.