LoginSignup
12
11

More than 5 years have passed since last update.

itunesのトップ無料アプリ順位及びReview情報取得方法

Posted at

今日は簡単にitunesのトップ無料アプリデータとReview情報を取得してみます

itunesからトップ無料アプリデータをRSS情報として取得して、そのアプリのReview情報の取得ができます。

topfreeapplications : トップ無料アプリの順位情報取得API

   limit:取得したい件数、type:jsonかxmlどちらを指定

customerreviews : アプリのReview情報取得API

   id: アプリのID、type:jsonかxmlどちら指定

 実際やってみましょう。

filename
    //トップ無料アプリデータ取得
    $url = "https://itunes.apple.com/jp/rss/topfreeapplications/limit=" . $appCnt . "/" . $type;

    $json = file_get_contents($url,true);

    $rank = json_decode($json,true);

    $jsonData = new JsonData();

    $rankNum = 1;

    foreach ($rank['feed']['entry'] as $row) {

        $appInfo = new App();
        $id = $row["id"]['attributes']['im:id'];        //APPID
        $appInfo->app_rank = $rankNum;                  //ランキング
        $appInfo->app_id = $id;
        $appInfo->app_name = $row["im:name"]['label'];  //アプリ名
        $appInfo->summary = $row["summary"]['label'];  //アプリ説明
        $appInfo->app_imgUrl = $row["im:image"];        //アプリのScreenShortイメージリンク

        //Review情報取得
        $reviewUrl = "http://itunes.apple.com/jp/rss/customerreviews/id=" . $id . "/sortby=mostrecent/" . $type;

        $reviewJson = file_get_contents($reviewUrl,true);
        $reviewInfo = json_decode($reviewJson,true);
        $reviewData = $reviewInfo['feed']['entry'];

        for($i=0; $i < count($reviewData); $i++) {

            if($i==0){
                continue;
            }

            $rev = new AppReview();
            $rev->name =$reviewData[$i]["author"]["name"]['label'];     //作成者名
            $rev->title = $reviewData[$i]["title"]['label'];        //Reviewタイトル
            $rev->content = $reviewData[$i]["content"]['label'];        //Review内容
            $rev->content_url = $reviewData[$i]["author"]['uri']['label'];  //Review URL
            $rev->rating = $reviewData[$i]["im:rating"]['label'];       //Review評価
            $rev->version = $reviewData[$i]["im:version"]['label'];     //Version情報
            array_push($appInfo->appreviews,$rev);
        }
        array_push($jsonData->reviews, $appInfo);

        $rankNum++;
    }
12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11