2

我正在使用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'];
}
4

1 回答 1

1

Unfortunately the API does not support this. You only get a List of up to 1 review snippet for the business.

The reviews array looks like this:

[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
                )

        )
于 2014-03-16T21:33:11.747 回答