サンプル・プログラム
サンプル・プログラムの実行例
APIキーの入手方法
API キーは日テレ WebAPIから「ニュース検索API」を選択し、画面の最下段で利用規約に同意することで発行してもらえる。無料である。
日テレ・ニュース検索API
URL |
---|
http://appli.ntv.co.jp/ntv_WebAPI/news/ |
項目名 | フィールド名 | 型 | 内 容 |
---|---|---|---|
APIキー | key | string | 【必須】APIキー |
検索文字列 | word | string | 【必須】検索する文字列(シフトJISでURLエンコード)。 複数指定の場合は半角スペースで区切って指定。複数指定の場合はAND条件で検索 |
検索開始年月日 | period_start | string | 【オプション】検索開始年月日を指定する。YYYYMMDD形式。 |
検索終了年月日 | period_end | string | 【オプション】検索終了年月日を指定する。YYYYMMDD形式。 |
サンプル・プログラムの解説:準備
0025: //APIキー:http://www.ntv.co.jp/appli/api/ からニュース検索APIを選択し入手
0026: define('API_KEY', '*****************************************************');
サンプル・プログラムの解説:ツールチップ
0052: <script type="text/javascript">
0053: this.imagePreview = function(){
0054: /* CONFIG */
0055: xOffset = 10;
0056: yOffset = 30;
0057:
0058: // these 2 variable determine popup's distance from the cursor
0059: // you might want to adjust to get the right result
0060:
0061: /* END CONFIG */
0062: $("a.preview").hover(function(e){
0063: this.t = this.title;
0064: this.title = "";
0065: var c = (this.t != "") ? "" + this.t : "";
0066: $("body").append("");
0067: $("#preview")
0068: .css("top",(e.pageY - xOffset) + "px")
0069: .css("left",(e.pageX + yOffset) + "px")
0070: .fadeIn("fast");
0071: },
0072: function() {
0073: this.title = this.t;
0074: $("#preview").remove();
0075: });
0076: $("a.preview").mousemove(function(e) {
0077: $("#preview")
0078: .css("top",(e.pageY - xOffset) + "px")
0079: .css("left",(e.pageX + yOffset) + "px");
0080: });
0081: };
0082:
0083: // starting the script on page load
0084: $(document).ready(function() {
0085: imagePreview();
0086: });
0087: </script>
0088: <style type="text/css">
0089: #preview{
0090: position: absolute;
0091: border: 3px solid #333;
0092: background: #444;
0093: padding: 5px;
0094: display: none;
0095: color: #FFF;
0096: text-align: center;
0097: }
0098: </style>
ツールチップに画像を表示させる(JavaScript Arcive)を参考にしている。
サンプル・プログラムの解説:一覧表示
一覧表示処理は、「PHP で Google ニュースの見出しを表示」を踏襲している。
参考サイト
- 日テレ・ニュース検索API
- ツールチップに画像を表示させる:JavaScript Arcive
- PHP で Google ニュースの見出しを表示:ぱふぅ家のホームページ