目標は商店街をつくる事なんです。

あきらめてるわけじゃないんです。今やっていることが、必ず力になると思うんです。

はてな大好き人間のiPhone(iTunes Search API)

こんばんわ。いたかなやです。

今日も来て頂いてありがとうございます。


先日のこの記事に関して、

iPhone6なんてもう古い?次次次世代iPhone - 目標は商店街をつくる事なんです。

id:kaz-cozさんから
ブラウザクラッシャーですか。
②直リンク大丈夫ですか?

という御指摘をいただきました。ありごとうございます。


①に関しては、そのようなつもりは無かったのですが、確かにそうなっていましたね。なので、iPhone31くらいで止まるように設定させて頂きました。ご迷惑をおかけしました。


②に関しても、APIがあるのだから大丈夫だろうと勝手な想像をしていましたが、利用規約みたいなものを読み返してみると、

iTunes, App Store, iBooks, and Mac App Store Affiliate Resources - Search API

「(v) is not used for independent entertainment value apart from its promotional purpose;」の部分、ひっかかってました・・・・汗
なので、こちらもアイコンをクリックすると、iTunesのページに飛べるように修正しておきました。これでおそらく大丈夫なはずです。。。たぶん

本当に御指摘ありがとうございました。


合わせて今日は、「iTunes Search API」の使い方をまとめておきたいと思います。
ついでにこんなのも作ってしまいました。

iPhoneアプリ検索】
好きなキーワードでアプリを検索してみよう!

<style>
	.base{
		position:absolute;
	}
	.icon{
		position:absolute;
		border-radius: 10px;
		width:40px;
		height:40px;
	}
	.name{
		position:absolute;
		width:45px;
		height:10px;
		background-color:black;
		color:white;
		font-size:8px;
		overflow:hidden;
		text-align:center;
	}
</style>
<script>
	var movepageurl=new Array();
	document.write('<input type="text" id="searchText">');
	document.write('<select id="media"><option value="movie">movie</option><option value="podcast">podcast</option><option value="music">music</option><option value="musicVideo">musicVideo</option><option value="audiobook">audiobook</option><option value="shortFilm">shortFilm</option><option value="tvShow">tvShow</option><option value="software" selected>software</option><option value="ebook">ebook</option><option value="all">all</option></select>');
	document.write('<input type="button" value="search!" onclick="searchApps()">');
	document.write('<div id="iphoneBase" style="position:relative;">');
	document.write('<img class="base" id="iphone0" src="http://itakanaya9.chobi.net/img/iphone0.png">');
	document.write('<img class="base" id="iphone1" style="top:418px;" src="http://itakanaya9.chobi.net/img/iphone2.png">');
	document.write("<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>");
		for(var i=0;i<6;i++){
			for(var j=0;j<4;j++){
				var id=i*4+j;
				var t=81+i*57;
				var l=25+j*50;
				document.write('<img class="icon" id="icon'+id+'" style="top:'+t+'px;left:'+l+'px;" onclick="movepage('+id+')">');
				document.write('<div class="name" id="name'+id+'" style="top:'+(t+41)+'px;left:'+(l-2)+'px;"></div>');
			}
		}
	document.write('</div>');
	function searchApps(){
		var media = document.getElementById('media').value;
		var text = document.getElementById('searchText').value;
		var script = document.createElement('script');
		script.src = "http://itunes.apple.com/search?term="+text+"&country=jp&media="+media+"&limit=24&callback=cb";
		document.head.appendChild(script);
	}
	function cb(d){
		for(var i=0;i<24;i++){
			document.getElementById("icon"+i).src=d.results[i].artworkUrl100;
			document.getElementById("name"+i).innerHTML=d.results[i].trackName;
			movepageurl[i]=d.results[i].artistViewUrl;
		}
	}
	function movepage(id){
		window.open(movepageurl[id]);
	}
</script>

まずは【Parameter Key】に関して、

term検索テキスト
country国を指定
・jp:日本
media検索したいメディアのタイプ
・movie
podcast
・music
・musicVideo
・audiobook
・shortFilm
・tvShow
・software
・ebook
・all
callbackコールバック関数指定
limit検索数を指定

詳しくはこちら→iTunes, App Store, iBooks, and Mac App Store Affiliate Resources - Search API




次に【Result Key】です。

kind検索結果の種類
trackNameトラック名
(アプリ名)
artworkUrl100イコン画像のURL
artistViewUrliTunesページのURL

詳しくはこちら→http://itunes.apple.com/search?term=hatena&country=jp&media=software&limit=24&callback=cb




アプリだけでなく、音楽やムービーも検索できるみたいですね。すごい!!
みなさんも良かったら使って見て下さい。

f:id:itakanaya9:20140216213850p:plain

iOS SDK Programming A Beginners Guide (Beginner's Guide)

iOS SDK Programming A Beginners Guide (Beginner's Guide)