■ReadAPIを使用したサンプルコード
※サンプルコードはjQueryを使用しています。
参考)サンプルコード
※“***************************” の部分はアカウントのReadAPIトークンを指定してください。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/Javascript"> function loadEqMeta(param, callbackname) { // token var token = "***************************"; // API reference var protocol = (window.location.protocol == 'https:' ? 'https://' : 'http://'); var apiBase = protocol + "api01-platform.stream.co.jp"; // api name var apiPathByParam = "/apiservice/getMediaByParam/"; // URL create var apiUrl = apiBase; apiUrl += apiPathByParam; apiUrl += "?token=" + token; // mid apiUrl += (param.mid == null) ? "" : "&mid=" + encodeURI(param.mid.join()) // API keyword apiUrl += (param.api_keywords == null) ? "" : "&api_keywords=" + encodeURI(param.api_keywords); // page size apiUrl += (param.pageSize == null) ? "" : "&pageSize=" + param.pageSize; // page# apiUrl += (param.pageNumber == null) ? "" : "&pageNumber=" + param.pageNumber; // active_flg apiUrl += (param.active_flg == null) ? "" : "&active_flg=" + param.active_flg; // insert_date if (param.insert_date != null) { apiUrl += (param.insert_date.to == null) ? "" : "&insert_date_to=" + param.insert_date.to; apiUrl += (param.insert_date.from == null) ? "" : "&insert_date_from=" + param.insert_date.from; } // update_date if (param.update_date != null) { apiUrl += (param.update_date.to == null) ? "" : "&update_date_to=" + param.update_date.to; apiUrl += (param.update_date.from == null) ? "" : "&update_date_from=" + param.update_date.from; } // publication_date if (param.publication_date != null) { apiUrl += (param.publication_date.to == null) ? "" : "&publication_date_to=" + param.publication_date.to; apiUrl += (param.publication_date.from == null) ? "" : "&publication_date_from=" + param.publication_date.from; } // expiration_date if (param.expiration_date != null) { apiUrl += (param.expiration_date.to == null) ? "" : "&expiration_date_to=" + param.expiration_date.to; apiUrl += (param.expiration_date.from == null) ? "" : "&expiration_date_from=" + param.expiration_date.from; } // sort param if (param.sort != null){ apiUrl += (param.sort[0].order == null) ? "" : "&sort1_order=" + param.sort[0].order; apiUrl += (param.sort[0].by == null) ? "" : "&sort1_by=" + param.sort[0].by; apiUrl += (param.sort[1].order == null) ? "" : "&sort2_order=" + param.sort[1].order; apiUrl += (param.sort[1].by == null) ? "" : "&sort2_by=" + param.sort[1].by; } // callbackname apiUrl += (callbackname == null) ? "" : "&callback=" + callbackname; // option apiUrl += (param.opt == null) ? "" : "&opt=" + param.opt; // add to header var objScript = document.createElement("script"); objScript.src = apiUrl; document.getElementsByTagName("head")[0].appendChild(objScript); } var base64list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; function base64encode(s) { var t = '', p = -6, a = 0, i = 0, v = 0, c; while ((i < s.length) || (p > -6)) { if (p < 0) { if (i < s.length) { c = s.charCodeAt(i++); v += 8; } else { c = 0; } a = ((a & 255) << 8) | (c & 255); p += 8; } t += base64list.charAt((v > 0) ? (a >> p) & 63 : 64); p -= 6; v -= 6; } return t; } function callApi() { var param = new Object(); // mid var midString= $('#mid').val(); var midArray= ""; if (midString != "") { midArray = midString.split(","); } param.mid = midArray; param.api_keywords = $('#api_keywords').val() == "" ? null : $('#api_keywords').val(); param.pageSize = $('#pageSize').val() == "" ? null : $('#pageSize').val(); param.pageNumber = $('#pageNumber').val() == "" ? null : $('#pageNumber').val(); param.active_flg = $('#active_flg').val() == "" ? null : $('#active_flg').val(); // insert_date var insert_date_array = {}; insert_date_array.from = $('#insert_date_from').val() == "" ? null : $('#insert_date_from').val(); insert_date_array.to = $('#insert_date_to').val() == "" ? null : $('#insert_date_to').val(); param.insert_date = insert_date_array; // update_date var update_date_array = {}; update_date_array.from = $('#update_date_from').val() == "" ? null : $('#update_date_from').val(); update_date_array.to = $('#update_date_to').val() == "" ? null : $('#update_date_to').val(); param.update_date = update_date_array; // publication_date var publication_date_array = {}; publication_date_array.from = $('#publication_date_from').val() == "" ? null : $('#publication_date_from').val(); publication_date_array.to = $('#publication_date_to').val() == "" ? null : $('#publication_date_to').val(); param.publication_date = publication_date_array; // expiration_date var expiration_date_array = {}; expiration_date_array.from = $('#expiration_date_from').val() == "" ? null : $('#expiration_date_from').val(); expiration_date_array.to = $('#expiration_date_to').val() == "" ? null : $('#expiration_date_to').val(); param.expiration_date = expiration_date_array; // sort var sort1_order = $('#sort1_order').val() == "" ? null : $('#sort1_order').val(); var sort1_by = $('#sort1_by').val() == "" ? null : $('#sort1_by').val(); var sort2_order = $('#sort2_order').val() == "" ? null : $('#sort2_order').val(); var sort2_by = $('#sort2_by').val() == "" ? null : $('#sort2_by').val(); if (sort1_order != null || sort1_by != null || sort2_order != null || sort2_by != null ) { var sortArray = [{ order: sort1_order, by: sort1_by }, { order: sort2_order, by: sort2_by }]; param.sort = sortArray; } var callback = $('#callback_name').val() == "" ? 'searchResultEq' : $('#callback_name').val(); var result = loadEqMeta(param, callback); } function searchResultEq(result){ var str = ""; if (result.meta[0].exlink[1] == null){ str += "ok"; } $('#result').html(":" + str); } </script> </head>
<body> <table border="0"> <p>---API引数---</p> <tr> <td width="100">api_keywords:</td> <td width="200"> <input id="api_keywords" type="text" value=""/> </td> </tr> <tr> <td width="100">pageSize:</td> <td width="200"> <input id="pageSize" type="text" value="" /> </td> </tr> <tr> <td width="100">pageNumber:</td> <td width="200"> <input id="pageNumber" type="text" value="" /> </td> </tr> <tr> <td>active_flg:</td> <td> <select name="active_flg" id="active_flg" value=""> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </td> </tr> <tr> <td width="100">mid:</td> <td width="200"> <input id="mid" type="text" value=""/> </td> </tr> <tr> <td width="100">insert_date from/to:</td> <td width="200"> <input id="insert_date_from" type="text" value=""/> </td> <td width="200"> <input id="insert_date_to" type="text" value=""/> </td> </tr> <tr> <td width="100">update_date from/to:</td> <td width="200"> <input id="update_date_from" type="text" value=""/> </td> <td width="200"> <input id="update_date_to" type="text" value=""/> </td> </tr> <tr> <td width="100">publication_date from/to:</td> <td width="200"> <input id="publication_date_from" type="text" value=""/> </td> <td width="200"> <input id="publication_date_to" type="text" value=""/> </td> </tr> <tr> <td width="100">expiration from/to:</td> <td width="200"> <input id="expiration_from" type="text" value=""/> </td> <td width="200"> <input id="expiration_to" type="text" value=""/> </td> </tr> <tr> <td width="100">sort1 order/by:</td> <td width="200"> <input id="sort1_order" type="text" value=""/> </td> <td width="200"> <input id="sort1_by" type="text" value=""/> </td> </tr> <tr> <td width="100">sort2 order/by:</td> <td width="200"> <input id="sort2_order" type="text" value=""/> </td> <td width="200"> <input id="sort2_by" type="text" value=""/> </td> </tr> <tr> <td width="100">callback_name:</td> <td width="200"> <input id="callback_name" type="text" value=""/> </td> </tr> </table> <br> </select> </tr> <tr> </table> <br> <form name="test"> <input type="button" onClick="callApi()" value="getMediaByParam" /> </form> <br> <p>---API取得値---</p> <div id="result"></div> </body> </html>
|