edwinhoksberg / trustpilot-api
一个用于解析和显示Trustpilot评论的简单库。
dev-master
2015-01-30 23:01 UTC
Requires
- php: >=5.4
This package is auto-updated.
Last update: 2024-09-20 10:03:32 UTC
README
此库是一个用于显示TrustPilot评论的简单类。
需要至少PHP版本5.4。
如何安装
使用composer
在您的终端中执行此命令
composer require edwinhoksberg/trustpilot-api:dev-master
或将此行添加到您的composer.json中
"require": {
"edwinhoksberg/trustpilot-api": "dev-master"
}
然后运行
composer update
不使用composer
将此行添加到您的PHP应用的顶部
require 'src/TrustPilot.php';
如何使用
// Initialize the API $trustpilot = new \TrustPilot\Api('1234567');
// Show site total score $trustpilot->getRatingScore(); // Output: 88
// Show site stars $trustpilot->getRatingStars(); // Output: 4
// Show number of stars for a specific star $stars = $trustpilot->getReviewStarDistrubution(); echo 'This site has ' . $stars[5] . ' ratings of five stars.'; // Output: This site has 27 ratings of five stars.
// Dump the data from a random review var_dump( $trustpilot->getRandomReview() ); // Output: array(10) { ["title"]=> string(22) "Very good and excellent prices" ["content"]=> string(22) "Very good and excellent prices, etc..." ["name"]=> string(21) "John Doe" ["url"]=> string(58) "http://www.trustpilot.nl/review/www.mysite.nl#1234567" ["language"]=> string(5) "en-US" ["score"]=> int(100) ["stars"]=> int(5) ["score_value"]=> string(10) "Excellent" ["timestamp"]=> int(1418866304) ["rating_images"]=> array(3) { ["small"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/s/5.png" ["medium"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/m/5.png" ["large"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/l/5.png" } }
// Display all reviews var_dump( $trustpilot->getAllReviews() ); // Output: array(1) { [0]=> array(10) { ["title"]=> string(22) "Very good and excellent prices" ["content"]=> string(22) "Very good and excellent prices, etc..." ["name"]=> string(21) "John Doe" ["url"]=> string(58) "http://www.trustpilot.nl/review/www.mysite.nl#1234567" ["language"]=> string(5) "en-US" ["score"]=> int(100) ["stars"]=> int(5) ["score_value"]=> string(10) "Excellent" ["timestamp"]=> int(1418866304) ["rating_images"]=> array(3) { ["small"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/s/5.png" ["medium"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/m/5.png" ["large"]=> string(50) "//s.trustpilot.com/images/tpelements/stars/l/5.png" } } [1]=> ... [2]=> ... }