[英]Assistance using an API using a php tpl file
I am going to level with you guys/gals. 我要和你们/加仑水平。 I have never used an API that I haven't copied and pasted from google/twitter etc.
我从未使用过从未从google / twitter等复制和粘贴的API。
I have a tpl file written in php code. 我有一个用php代码编写的tpl文件。 Within this tpl file I have a section that relates to a review counter.
在这个tpl文件中,我有一个与评论计数器相关的部分。 (So how many reviews this product on this page has been submitted)
(因此,此页面上此产品已提交了多少评论)
I am trying to replace this 'native counter' for the cms: 我正在尝试将cms的“本地计数器”替换为:
<?php echo $reviews; ?> <img align="absmiddle" class="fade-image" src="catalog/view/theme/simplegreat/image/stars-<?php echo $rating; ?>.png" alt="<?php echo $reviews; ?>" /></div>
I am wanting this code which returns the review from the native review system, with the API for a third party review system. 我想要这个代码,它从本机审阅系统返回审阅,并带有第三方审阅系统的API。 The system is in place where it needs to be, however I need to implement their API to grab the review count and rating from their 3rd party server.
该系统已放置在需要的地方,但是我需要实现他们的API,以从其第三方服务器获取评论数和评分。
So the API I am trying to use is: HERE 所以我要使用的API是: HERE
So I am trying to use this API to output the following: 因此,我尝试使用此API输出以下内容:
If someone could help me through this API and hopefully I can learn a little more about APIs with php and how they function in the process. 如果有人可以通过此API帮助我,希望我可以了解有关php的API及其在此过程中如何工作的更多信息。 Thanks.
谢谢。
It's quite easy, just follow the documentation :-) 这很容易,只需遵循文档即可:-)
The documentation states: 该文档指出:
/products/{app_key}/{sku}/bottomline?callback={pjson_callback}
Given
product_sku
(unique identifier of the product within your domain), and aapp_key
, the call returns the total reviews and average score of this product.给定
product_sku
(您域内产品的唯一标识符)和app_key
,调用将返回该产品的总评论和平均得分。Required params:
必需的参数:
appkey
- the app key of the account sku - id of the product in the website, should be consistent with the product_id that is used in the product pageappkey
帐户sku的应用程序密钥-网站中产品的ID,应与产品页面中使用的product_id一致Optional params:
callback
- jsonp call back function可选参数:
callback
-jsonpcallback
函数
They even give you an example in PHP: 他们甚至为您提供了PHP中的示例:
Request (this is how you use the API) 请求 (这是您使用API的方式)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://yotpoapi.apiary.io/products/{app_key}/{sku}/bottomline?callback={pjson_callback}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
Response (This is what you'll get back) 响应 (这是您会得到的)
200 (OK)
Content-Type: application/json
{
"status":{
"code":200,
"message":"OK"
},
"response":{
"bottomline":{
"average_score":4.52,
"total_reviews":23
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.