使用PHP进行Yelp Business API 2.0列表评论

时间:2014-02-23 00:50:48

标签: php json yelp

我正在使用http://www.yelp.com/developers/documentation/v2/business

中记录的Yelp Business API v2.0

我的目标是列出特定业务的三个评论,使用PHP进行API调用并检索json。但是,我似乎只能通过API获取一个评论。我已准备好脚本循环并显示返回的所有评论。如何调用API以检索多个评论?

我尝试使用搜索API,但它似乎也没有显示多个评论。

$unsigned_url = "http://api.yelp.com/v2/business/[the-business-name]";

...

// Handle Yelp response data
$response = json_decode($data, TRUE);

// for business API
foreach($response['reviews'] as $item) {
    print '<img src="' . $item['user']['image_url'] . '" alt="" /> ';
    print $item['user']['name'];
    print ' ';
    print '<img src="' . $item['rating_image_url'] . '" alt="" /><br/>';
    print $item['excerpt'];
}

1 个答案:

答案 0 :(得分:1)

不幸的是,API不支持此功能。 你只得到一个 List of up to 1 review snippet for the business

评论数组如下所示:

[reviews] => Array
        (
            [0] => stdClass Object
                (
                    [rating] => 5
                    [excerpt] => I spoke with Kenneth personally and he was the one to actually come and do the work.  Price he quoted to me on the phone was still the price I was charged -...
                    [time_created] => 1370286342
                    [rating_image_url] => http://s3-media1.ak.yelpcdn.com/assets/2/www/img/f1def11e4e79/ico/stars/v1/stars_5.png
                    [rating_image_small_url] => http://s3-media1.ak.yelpcdn.com/assets/2/www/img/c7623205d5cd/ico/stars/v1/stars_small_5.png
                    [user] => stdClass Object
                        (
                            [image_url] => http://s3-media4.ak.yelpcdn.com/assets/2/www/img/cc4afe21892e/default_avatars/user_medium_square.png
                            [id] => mFrv54j7_7bRdqlmb4WLsA
                            [name] => Nancy R.
                        )

                    [rating_image_large_url] => http://s3-media3.ak.yelpcdn.com/assets/2/www/img/22affc4e6c38/ico/stars/v1/stars_large_5.png
                    [id] => gFrVMC7pe0IW1lzpqfCwrg
                )

        )