Bing Web Search API (Bing API v5)

リクエスト

https://bingapis.azure-api.net/api/v5/search/
Search API - V5 | Microsoft Cognitive Services
https://api.cognitive.microsoft.com/bing/v5.0/search/

2016/06以降リクエスト先のURIが、https://bingapis.azure-api.net/api/v5/からhttps://api.cognitive.microsoft.com/bing/v5.0/へ変更されています。Release Notes | MSDN

GET https://bingapis.azure-api.net/api/v5/search/?q=keyword HTTP/1.1
Host: bingapis.azure-api.net
Ocp-Apim-Subscription-Key: ***

ヘッダ

ヘッダの一部
ヘッダ  
Ocp-Apim-Subscription-Key [必須]
User-Agent  

Subscription keyはsubscriptionsのページから[Request new trials]へ進み、Bing Searchを選択して[Subscribe]をクリックすることで取得できます。

パラメータ

パラメータの一部
パラメータ 意味
q 検索キーワード [必須]
count 結果の数。上限は50。既定では10
offset 結果のオフセット
mkt 対象とする国。値はMarket Codesで指定
safesearch アダルトコンテンツのフィルタ
   
Query Parameters - Web Search API Reference | MSDN

制限

Bing Web Search APIの利用は、Free版では

  • 3か月間は、1000トランザクション/月 (1か月あたり、1000回のリクエスト)
  • 5トランザクション/秒

に制限されています。 Microsoft Cognitive Services - Preview pricing Pricing options - Microsoft Cognitive Services - Bing Web Search API

このAPIを継続して利用するには、$3/月 (S1 Standard) 以上の有料プランへの加入が必要です。

サンプルコード

$q = 'sushi';

$subscriptionKey = '***';
$serviceRoot = 'https://bingapis.azure-api.net/api/v5/search/';


$ch = curl_init( $serviceRoot.'?'.http_build_query( compact( 'q' ) ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Ocp-Apim-Subscription-Key: '.$subscriptionKey ) );

$response = curl_exec( $ch );
curl_close( $ch );

header( 'Content-Type: application/json' );
echo $response;

レスポンス

{
  "_type" : "SearchResponse",
  "webPages" :
  {
    "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fsearch%3fq%3dsushi&p=DevEx,5320.1",
    "totalEstimatedMatches" : 15100000,
    "value" : [
      {
        "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#WebPages.0",
        "name" : "Flashタイピング 【寿司打 - SushiDA -】",
        "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2f&p=DevEx,5074.1",
        "displayUrl" : "typing.sakura.ne.jp\/sushida",
        "snippet" : "「寿司打」はローマ字入力用のタイピング練習ゲームです。 お皿が流れてしまう前に画面の文字をタイプして、どれだけモトを取れるか(= たくさん食べられるか)を競います。 無料&ブラウザで遊べますので、ちょっとした休み時間 ...",
        "deepLinks" : [
          {
            "name" : "Play",
            "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2fsimple%2fshot.html&p=DevEx,5067.1"
          },
          {
            "name" : "ご利用規約",
            "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2fkiyaku.html&p=DevEx,5068.1"
          },
          {
            "name" : "Q&A",
            "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2fhelp.html&p=DevEx,5069.1"
          },
          {
            "name" : "ローマ字対応表",
            "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2ftaiou.html&p=DevEx,5070.1"
          },
          {
            "name" : "寿司アイコン",
            "url" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2ftyping.sakura.ne.jp%2fsushida%2ficon.html&p=DevEx,5071.1"
          }
        ],
        "dateLastCrawled" : "2016-05-07T12:48:00"
      },
      ...
    ]
  },
  "images" :
  {
    "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#Images",
    "readLink" : "https:\/\/bingapis.azure-api.net\/api\/v5\/images\/search?q=sushi&qpvt=sushi&qpvt=sushi&qpvt=sushi",
    "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fimages%2fsearch%3fq%3dsushi%26qpvt%3dsushi%26qpvt%3dsushi%26qpvt%3dsushi&p=DevEx,5030.1",
    "isFamilyFriendly" : true,
    "value" : [
      {
        "name" : "Nagase outlines top Japanese food trends - Ingredients Network",
        "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fimages%2fsearch%3fq%3dsushi%26id%3d7748C161B7F51EFE56A91BC969BC7898C17EBF90%26FORM%3dIQFRBA&p=DevEx,5244.1",
        "thumbnailUrl" : "https:\/\/tse1.mm.bing.net\/th?id=OIP.Maab9611b2bfcda3b6a79b292a883c0d6o0&pid=Api",
        "datePublished" : "2015-06-24T23:17:00",
        "contentUrl" : "http:\/\/insights.ingredientsnetwork.com\/wp-content\/uploads\/2015\/01\/japanese-food.jpg",
        "hostPageUrl" : "http:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=http%3a%2f%2finsights.ingredientsnetwork.com%2fnagase-outlines-top-japanese-food-trends&p=DevEx,5321.1",
        "contentSize" : "137220 B",
        "encodingFormat" : "jpeg",
        "hostPageDisplayUrl" : "http:\/\/insights.ingredientsnetwork.com\/nagase-outlines-top-japanese-food-trends",
        "width" : 1500,
        "height" : 1000,
        "thumbnail" :
        {
          "width" : 300,
          "height" : 200
        }
      },
      ...
    ],
    "displayShoppingSourcesBadges" : false,
    "displayRecipeSourcesBadges" : true
  },
  "relatedSearches" :
  {
    "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#RelatedSearches",
    "value" : [
      {
        "text" : "sushi食べたい",
        "displayText" : "sushi食べたい",
        "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fsearch%3fq%3dsushi%25e9%25a3%259f%25e3%2581%25b9%25e3%2581%259f%25e3%2581%2584&p=DevEx,5348.1"
      },
      ...
    ]
  },
  "videos" :
  {
    "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#Videos",
    "readLink" : "https:\/\/bingapis.azure-api.net\/api\/v5\/videos\/search?q=sushi",
    "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fvideos%2fsearch%3fq%3dsushi&p=DevEx,5053.1",
    "isFamilyFriendly" : true,
    "value" : [
      {
        "name" : "Nigiri Sushi (Nigirizushi Recipe) and Sushi Socks 握り寿司&寿司 ...",
        "description" : "How to Make Nigiri Sushi 握り寿司の作り方 字幕表示可 材料(日本語)↓ The winner for the sushi socks is insanerikki. Congratulations and thank you ...",
        "webSearchUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.bing.com%2fvideos%2fsearch%3fq%3dsushi%23view%3ddetail%26mid%3dD0CCEB803506E75F830BD0CCEB803506E75F830B&p=DevEx,5332.1",
        "thumbnailUrl" : "https:\/\/tse1.mm.bing.net\/th?id=OVP.V03271a1adcd84a18d086f13a0a2d7793&pid=Api",
        "datePublished" : "2014-12-12T07:03:02",
        "publisher" : [
          {
            "name" : "YouTube"
          }
        ],
        "contentUrl" : "https:\/\/www.youtube.com\/watch?v=xLV1ZHEAaS0",
        "hostPageUrl" : "https:\/\/www.bing.com\/cr?IG=AAA&CID=BBB&rd=1&h=CCC&v=1&r=https%3a%2f%2fwww.youtube.com%2fwatch%3fv%3dxLV1ZHEAaS0&p=DevEx,5331.1",
        "encodingFormat" : "mp4",
        "hostPageDisplayUrl" : "https:\/\/www.youtube.com\/watch?v=xLV1ZHEAaS0",
        "width" : 1280,
        "height" : 720,
        "duration" : "PT5M49S",
        "motionThumbnailUrl" : "https:\/\/tse1.mm.bing.net\/th?id=OM.C4Nf5wY1gOvM0A&pid=Api",
        "embedHtml" : "<iframe width=\"1280\" height=\"720\" src=\"http:\/\/www.youtube.com\/embed\/xLV1ZHEAaS0?autoplay=1\" frameborder=\"0\" allowfullscreen><\/iframe>",
        "allowHttpsEmbed" : true,
        "viewCount" : 623428,
        "thumbnail" :
        {
          "width" : 300,
          "height" : 168
        },
        "allowMobileEmbed" : true
      },
      ...
    ],
    "scenario" : "List"
  },
  "rankingResponse" :
  {
    "mainline" :
    {
      "items" : [
        {
          "answerType" : "WebPages",
          "resultIndex" : 0,
          "value" :
          {
            "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#WebPages.0"
          }
        },
        ...
      ]
    },
    "sidebar" :
    {
      "items" : [
        {
          "answerType" : "Places",
          "resultIndex" : 0,
          "value" :
          {
            "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#Places.0"
          }
        },
        {
          "answerType" : "RelatedSearches",
          "value" :
          {
            "id" : "https:\/\/bingapis.azure-api.net\/api\/v5\/#RelatedSearches"
          }
        }
      ]
    }
  }
}
Response Objects - Web Search API Reference | MSDN

エラー

リソースが見つからない
{ "statusCode": 404, "message": "Resource not found" }

リソースが見つからない、まはた予期せずアクセスが拒否される場合には、Release NotesでAPIに変更がないか確認します。

Search APIへアクセスできない
{
  "_type": "ErrorResponse",
  "errors":
    [
      {
        "code": "DataSourceAccessDenied",
        "message": "AppID does not have access to the Data source: Search"
      }
    ]
}

Search APIの購読を申し込みます。

購読の期限切れ
{
  "error":
  {
    "code":"SubscriptionExpired",
    "message":"This subscription has expired."
  }
}

契約を確認します。

複数の技術系サイトから、まとめて検索