https://itunes.apple.com/us/rss/customerreviews/id=284882215/sortBy=mostRecent/xml
其中,上述有三個主要可變動的參數:country(us), app id (284882215), format(xml)
最近比較愛 json 的:
https://itunes.apple.com/us/rss/customerreviews/id=284882215/sortBy=mostRecent/json
想要台灣區評價:
https://itunes.apple.com/tw/rss/customerreviews/id=284882215/sortBy=mostRecent/json
問題應該就是 country 到底有哪些,可以用既定資料每個都抓一遍啦。
對於格式有興趣的可以用得到可讀性較佳的資料格式:
$ curl https://itunes.apple.com/tw/rss/customerreviews/id=284882215/sortBy=mostRecent/json | python -mjson.tool
若仔細看的話,還可以看到 User ID 、追蹤到 User 對其他款 app 評價等,此外,也有 first page 跟 last page 存取方式:
https://itunes.apple.com/tw/rss/customerreviews/page=1/id=284882215/sortby=mostrecent/json
https://itunes.apple.com/tw/rss/customerreviews/page=10/id=284882215/sortby=mostrecent/json
最大頁數只有到 10 而已(CustomerReviews RSS page depth is limited to 10)
至於要用 json 還是 xml 好?目前的心得是... json 會缺少 user comment updated 資訊,而 xml 卻也會碰到 format error 的情況 Orz 只能...看著辦了 XD
以 PHP 處理為例:
$ cat test.php
<?php
$app_id = '284882215';
$country_list = array( 'tw', 'us');
$format = 'xml';
$page_list = array(1,2,3,4,5,6,7,8,9,10);
foreach( $country_list as $country ) {
foreach( $page_list as $page ) {
$url = "https://itunes.apple.com/$country/rss/customerreviews/id=$app_id/page=$page/$format";
if ($format == 'json') {
$raw = json_decode(@file_get_contents($url), true);
//print_r($raw);
for ($i=1, $cnt=count($raw['feed']['entry']) ; $i<$cnt ; ++$i) {
print_r(array(
'user_id' => $raw['feed']['entry'][$i]['id']['label'],
'user_name' => $raw['feed']['entry'][$i]['author']['name']['label'],
'user_uri' => $raw['feed']['entry'][$i]['author']['uri']['label'],
'title' => $raw['feed']['entry'][$i]['title']['label'],
'content' => $raw['feed']['entry'][$i]['content']['label'],
'version' => $raw['feed']['entry'][$i]['im:version']['label'],
'rating' => $raw['feed']['entry'][$i]['im:rating']['label'],
));
}
} else {
$raw = simplexml_load_string(@file_get_contents($url));
//print_r($raw);
for($i=1, $cnt = count($raw->entry); $i<$cnt ; ++$i) {
//print_r($raw->entry[$i]);
$imAttrs = $raw->entry[$i]->children('im', true);
//print_r($imAttrs);
print_r(array(
'date' => (string)$raw->entry[$i]->updated,
'user_id' => (string)$raw->entry[$i]->id,
'user_name' => (string)$raw->entry[$i]->author->name,
'user_uri' => (string)$raw->entry[$i]->author->uri,
'title' => (string)$raw->entry[$i]->title,
'content' => (string)$raw->entry[$i]->content[0],
'version' => (string)$imAttrs->version,
'rate' => (string)$imAttrs->rating,
));
}
}
exit;
}
}
$ php test.php
Array
(
[date] => 2014-09-10T09:10:00-07:00
[user_id] => ###########
[user_name] => ###########
[user_uri] => https://itunes.apple.com/tw/reviews/id###########
[title] => 有Bug請改善
[content] => 點朋友的動態跑不出來!!
[version] => 14.0
[rating] => 1
)
Array
(
[date] => 2014-09-10T09:03:00-07:00
[user_id] => ###########
[user_name] => ###########
[user_uri] => https://itunes.apple.com/tw/reviews/id###########
[title] => 一直自動關掉
[content] => 用一用會一直自動跳掉,很頻繁,很煩。
[version] => 14.0
[rating] => 1
)
沒有留言:
張貼留言