2014-02-23 29 views
2

我现在用的是Yelp的业务API 2.0版作为http://www.yelp.com/developers/documentation/v2/business记录列表点评Yelp的业务API 2.0与PHP

我的目标是列出特定业务的3条评论中,使用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

不幸的是,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 
       ) 

     ) 
+0

这是不幸的。旧的API至少给三个评论,这是糟糕的,但至少有三个评论。现在API几乎没有意义。 –

+1

你可以尝试的其他东西是使用网络刮板。以下是我一直在研究的内容:http://inkbud.com/wp-content/plugins/juicyreviews/get_reviews.php和运行它的PHP:http://pastebin.com/JVDZgctv使用此库:http: //simplehtmldom.sourceforge.net/manual.htm祝你好运! – broinjc