LoginSignup
16
16

More than 5 years have passed since last update.

AppStoreのiOSアプリレビューをスプレットシートに書き込む (2018/12/30 現在)

Last updated at Posted at 2018-12-30

iOSアプリのレビューをスプレッドシートに書き込む要件があったのでメモ

【事前準備】 レビュー取得URL(XML)

  • id は、好きなアプリのIDを記載してください
  • 末尾をjsonにすると、JSON形式で取得できますが、日付が取得できなかった。
  • 1ページ50件、10ページ分まで取得できる

app_id の確認方法

app storeのURLより取得します

スクリーンショット 2018-12-29 23.59.02.png

【事前準備】 Appleから取得できるXMLの確認

entry 内のタグを取得する

<entry>
  <updated>時間</updated>
  <id>数字</id>
  <title>タイトル</title>
  <content type="text">コメント</content>
  <im:contentType term="Application" label="アプリケーション"/>
  <im:voteSum>0</im:voteSum>
  <im:voteCount>0</im:voteCount>
  <im:rating>5</im:rating>
  <im:version>1.0.0</im:version>
  <author>
    <name>ユーザー名</name>
    <uri>レビューURL</uri>
  </author>
  <link rel="related" href="https://〜"/>
  <content type="html">
    HTMLコード
  </content>
</entry>

※ im:contentTypeタグ、linkタグと contentタグのhtmlは対象外にしました。

【本題】 Google Apps Script からスプレットシートに書き込む

app_id、スプレッドシートのURL、シート名を変更して、getReview()を実行する

ポイント
- この処理で、最大500件のレビューを取得できる(500件以上は、Appleが保証していない)
- appleのNamespaceで少し迷った。

var app_id = 0123456789 // 取得したいアプリのapp_idに変更する
var sp_url = '<スプレットシートのURL>'; // 書き込みたいスプレッドシートに変更する
var spreadsheet = SpreadsheetApp.openByUrl(sp_url);
var sheet = spreadsheet.getSheetByName('シート1'); // 書き込みたいシート名に変更する

// Namespaceを取得する
var atomNS = XmlService.getNamespace('http://www.w3.org/2005/Atom');
var appleNS = XmlService.getNamespace('http://itunes.apple.com/rss');

function getReview() {
  _writeReview(_getEntries())
}

/*
 * XMLからentryの配列を取得する
 */
function _getEntries() {
  var entries = [];
  // 1ページから10ページまでを取得する ※1ページ 50件 ※Apple は10ページまでしか保証しない
  for(var i=1; i<=10; i++){
    var xml_url = "https://itunes.apple.com/jp/rss/customerreviews/id="+app_id+"/sortBy=mostRecent/page="+i+"/xml"
    var response = UrlFetchApp.fetch(xml_url).getContentText();
    var xml = XmlService.parse(response);
    var feed = xml.getRootElement();

    Array.prototype.push.apply(entries, feed.getChildren('entry',atomNS));
  }

  return entries;
  // 配列を逆順に(日付の古い順)
  // return entries.reverse();
}

/*
 * スプレッドシートにentryの配列を書き込む
 */
function _writeReview(entries) {
  // 1行目から始める
  var row = 1;
  for (var idx in entries) {
    sheet.getRange(row, 1).setValue(entries[idx].getChild('updated',atomNS).getText());
    sheet.getRange(row, 2).setValue(entries[idx].getChild('id',atomNS).getText());
    sheet.getRange(row, 3).setValue(entries[idx].getChild('title',atomNS).getText());
    sheet.getRange(row, 4).setValue(entries[idx].getChild('content',atomNS).getText());

    sheet.getRange(row, 5).setValue(entries[idx].getChild('voteSum',appleNS).getText());
    sheet.getRange(row, 6).setValue(entries[idx].getChild('voteCount',appleNS).getText());
    sheet.getRange(row, 7).setValue(entries[idx].getChild('rating',appleNS).getText());
    sheet.getRange(row, 8).setValue(entries[idx].getChild('version',appleNS).getText());

    var author = entries[idx].getChild('author',atomNS);
    sheet.getRange(row, 9).setValue(author.getChild('name',atomNS).getText());
    sheet.getRange(row, 10).setValue(author.getChild('uri',atomNS).getText());

    row++
  }
}
16
16
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
16
16