Google/APIカスタム検索
提供: 初心者エンジニアの簡易メモ
画像のAPIカスタム検索をする
APIキーを作成する
- https://cloud.google.com/console/project
- プロジェクトを作成する
- Custom Search API を有効にする
- 認証情報/APIキー作成/サーバーキーを作成を選択
- apiキーをメモしておく
カスタム検索IDを作成する
- https://cse.google.co.jp からカスタム検索を作成する
- 検索するサイトは必須なので一旦追加する(後で削除)
- 検索するサイトを"追加したサイトを重視して、サイト全体を検索する"に変更する
- 画像検索をONにする
- 検索エンジンIDをメモする(検索エンジンIDのボタンを押す)
API検索
APIキーと検索エンジンIDを入力してhttpsでアクセスする
ttps://www.googleapis.com/customsearch/v1?key={API_KEY}&cx={CUSTOM_SEARCH_ENGINE_ID}&q={SEARCH_WORDS}
API検索結果サンプル
{
"kind": "customsearch#search",
"url": {
"type": "application/json",
"template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
},
"queries": {
"nextPage": [
{
"title": "Google Custom Search - 初音ミク",
"totalResults": "314000",
"searchTerms": "初音ミク",
"count": 10,
"startIndex": 11,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "xxxxxxxxxxxxxxxxxxxxxxx"
}
],
"request": [
{
"title": "Google Custom Search - 初音ミク",
"totalResults": "314000",
"searchTerms": "初音ミク",
"count": 10,
"startIndex": 1,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "xxxxxxxxxxxxxxxxxxxxxxx"
}
]
},
"context": {
"title": "google-search-image"
},
"searchInformation": {
"searchTime": 0.46207,
"formattedSearchTime": "0.46",
"totalResults": "314000",
"formattedTotalResults": "314,000"
},
"items": [
{
"kind": "customsearch#result",
"title": "【初音ミク】みくみくにしてあげる Trance.ver【高画質版PV】 - YouTube",
"htmlTitle": "【\u003cb\u003e初音ミク\u003c/b\u003e】みくみくにしてあげる Trance.ver【\u003cb\u003e高画質\u003c/b\u003e版PV】 - YouTube",
"link": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"displayLink": "www.youtube.com",
"snippet": "2010年12月28日 ... MikuMikuDanceで初音ミクのPVを作ってみました。 使用したソフトは ○\nMikuMikuDance ○Illustrator8.0 ○Photoshop6.0 ○trakAxPC ○aviutl 映像の特殊\n効果についてはMMEや動画編集ソフト内のフィルタ、ネット上のフリー素材などを ...",
"htmlSnippet": "2010年12月28日 \u003cb\u003e...\u003c/b\u003e MikuMikuDanceで\u003cb\u003e初音ミク\u003c/b\u003eのPVを作ってみました。 使用したソフトは ○\u003cbr\u003e\nMikuMikuDance ○Illustrator8.0 ○Photoshop6.0 ○trakAxPC ○aviutl 映像の特殊\u003cbr\u003e\n効果についてはMMEや動画編集ソフト内のフィルタ、ネット上のフリー素材などを ...",
"cacheId": "kPs90mDoMboJ",
"formattedUrl": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"htmlFormattedUrl": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"pagemap": {
"cse_image": [
{
"src": "https://i.ytimg.com/vi/jdCOZQXUOfc/maxresdefault.jpg"
}
],
"videoobject": [
{
"url": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"name": "【初音ミク】みくみくにしてあげる♪ Trance.ver【高画質版PV】",
"description": "MikuMikuDanceで初音ミクのPVを作ってみました。 使用したソフトは ●MikuMikuDance ●Illustrator8.0 ●Photoshop6.0 ●trakAxPC ●aviutl 映像の特殊効果についてはMM...",
"paid": "False",
"channelid": "UCikruuwPw4bmp8lrETzParw",
"videoid": "jdCOZQXUOfc",
"duration": "PT3M28S",
"unlisted": "False",
"thumbnailurl": "https://i.ytimg.com/vi/jdCOZQXUOfc/maxresdefault.jpg",
"embedurl": "https://www.youtube.com/embed/jdCOZQXUOfc",
"playertype": "HTML5 Flash",
"width": "1280",
"height": "720",
"isfamilyfriendly": "True",
"regionsallowed": "AD,AE,AF,AG,AI,AL,AM,AO,AQ,AR,AS,AT,AU,AW,AX,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BL,BM,BN,BO,BQ,BR,BS,BT,BV,BW,BY,BZ,CA,CC,CD,CF,CG,CH,CI,CK,CL,CM,CN,CO,CR,CU,CV,CW,CX,CY,CZ,DE,DJ,DK,DM,DO,DZ,EC,EE,EG,EH...",
"interactioncount": "328987",
"datepublished": "2010-12-28",
"genre": "Music"
}
],
"person": [
{
"url": "http://www.youtube.com/user/AkutokuFinance"
}
],
"cse_thumbnail": [
{
"width": "300",
"height": "168",
"src": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTuej2ibtJfWDkK1D-_XWlA0b58Z52ozaF3TkL-M_ULCI0iJ8DqV8Ia02hA"
}
],
"metatags": [
{
"theme-color": "#e62117",
"title": "【初音ミク】みくみくにしてあげる♪ Trance.ver【高画質版PV】",
"og:site_name": "YouTube",
"og:url": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"og:title": "【初音ミク】みくみくにしてあげる♪ Trance.ver【高画質版PV】",
"og:image": "https://i.ytimg.com/vi/jdCOZQXUOfc/maxresdefault.jpg",
"og:description": "MikuMikuDanceで初音ミクのPVを作ってみました。 使用したソフトは ●MikuMikuDance ●Illustrator8.0 ●Photoshop6.0 ●trakAxPC ●aviutl 映像の特殊効果についてはMMEや動画編集ソフト内のフィルタ、ネット上のフリー素材などを使っています。 htt...",
"al:ios:app_store_id": "544007664",
"al:ios:app_name": "YouTube",
"al:ios:url": "vnd.youtube://www.youtube.com/watch?v=jdCOZQXUOfc&feature=applinks",
"al:android:url": "vnd.youtube://www.youtube.com/watch?v=jdCOZQXUOfc&feature=applinks",
"al:android:app_name": "YouTube",
"al:android:package": "com.google.android.youtube",
"al:web:url": "https://www.youtube.com/watch?v=jdCOZQXUOfc&feature=applinks",
"og:type": "video",
"og:video:url": "https://www.youtube.com/embed/jdCOZQXUOfc",
"og:video:secure_url": "https://www.youtube.com/embed/jdCOZQXUOfc",
"og:video:type": "text/html",
"og:video:width": "1280",
"og:video:height": "720",
"og:video:tag": "初音ミク",
"fb:app_id": "87741124305",
"twitter:card": "player",
"twitter:site": "@youtube",
"twitter:url": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"twitter:title": "【初音ミク】みくみくにしてあげる♪ Trance.ver【高画質版PV】",
"twitter:description": "MikuMikuDanceで初音ミクのPVを作ってみました。 使用したソフトは ●MikuMikuDance ●Illustrator8.0 ●Photoshop6.0 ●trakAxPC ●aviutl 映像の特殊効果についてはMMEや動画編集ソフト内のフィルタ、ネット上のフリー素材などを使っています。 htt...",
"twitter:image": "https://i.ytimg.com/vi/jdCOZQXUOfc/maxresdefault.jpg",
"twitter:app:name:iphone": "YouTube",
"twitter:app:id:iphone": "544007664",
"twitter:app:name:ipad": "YouTube",
"twitter:app:id:ipad": "544007664",
"twitter:app:url:iphone": "vnd.youtube://www.youtube.com/watch?v=jdCOZQXUOfc&feature=applinks",
"twitter:app:url:ipad": "vnd.youtube://www.youtube.com/watch?v=jdCOZQXUOfc&feature=applinks",
"twitter:app:name:googleplay": "YouTube",
"twitter:app:id:googleplay": "com.google.android.youtube",
"twitter:app:url:googleplay": "https://www.youtube.com/watch?v=jdCOZQXUOfc",
"twitter:player": "https://www.youtube.com/embed/jdCOZQXUOfc",
"twitter:player:width": "1280",
"twitter:player:height": "720"
}
],
"imageobject": [
{
"url": "https://i.ytimg.com/vi/jdCOZQXUOfc/maxresdefault.jpg",
"width": "1280",
"height": "720"
}
]
}
},
