###実現したいこと
Redmine APIを利用して、チケットの情報をGoogleスプレッドシートで一覧化したい。
そのために、Google Apps Script(GAS)でRedmineのDigest認証を通過して
json形式のデータを取得する必要がある。
どうすればいいか?
###前提
- Redmine API(REST API)を利用
- Googleスプレッドシート(Google Apps Script)を利用
###ソースコード
途中まで作ってみました。
最後のリクエスト時に、やはり失敗します。
1function redmineToGoogleSpreadsheet() { 2 3 // RedmineのURLを指定 4 var redmineUrl = "https://hogehoge.com/projects/hogehoge/"; 5 var redmineApiKey = "tekitou6T6nbGu5RUjYe3iN5NqrRL3twXtKB8"; 6 var redmineLimit = 100; 7 var url = redmineUrl + "issues.json?key=" + redmineApiKey + "&limit=" + redmineLimit; 8 9 // optionsを指定 10 var options = { 11 "validateHttpsCertificates":false, 12 "followRedirects":false, 13 "muteHttpExceptions":true, 14 "escaping":false 15 }; 16 17 // 最初のリクエスト 18 var response = UrlFetchApp.fetch(url,options); 19 20 // header情報を格納し、nonceを取得する 21 var headers = response.getAllHeaders(); 22 var key = "WWW-Authenticate"; 23 var arr = headers[key]; 24 var arr = arr.split(","); 25 var nonce = arr[1].replace('nonce="','').replace('"',''); 26 27 // 値を設定 28 var username = "username"; 29 var realm = "realm"; 30 var uri = "/projects/hogehoge/issues.json?key=tekitou6T6nbGu5RUjYe3iN5NqrRL3twXtKB8&limit=100"; 31 var algorithm = "MD5"; 32 var qop = "auth"; 33 var nc = "00000001"; 34 var cnonce = "f16367eeab5979c4"; 35 var pass = "pass"; 36 37 // 再度リクエストを投げる 38 var a1 = username + ":" + realm + ":" + pass; 39 var a2 = "GET:" + uri; 40 41 var da1 = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, a1); 42 var da2 = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, a2); 43 var da3 = da1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + da2; 44 var response2 = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, da3); 45 46 var options2 = { 47 'headers' : {'Authorization' : 'Digest username="' + username + '" , realm="' + realm + '" , nonce="' + nonce + '" , uri="' + uri + '" , algorithm="' + algorithm + '" , response="' + response2 + '" , qop="' + qop + '" , nc="' + nc + '" , cnonce="' + cnonce + '"' }, 48 "validateHttpsCertificates":false, 49 "followRedirects":false, 50 "muteHttpExceptions":true, 51 "escaping":false 52 }; 53 54 // 最後のリクエスト 55 var response3 = UrlFetchApp.fetch(url,options2); 56 57}
###備考
散々調べましたが、やり方がわからずで、こちらで質問させていただきました。
よろしくお願いいたします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/04 01:17