Created
January 10, 2015 13:42
-
-
Save masui/e65f3b24c19160ae17c4 to your computer and use it in GitHub Desktop.
Bingで画像検索
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://datamarket.azure.com/account/keys でキーを取得 | |
# window.bing_acctkey に入ってるものとする | |
window.bing_search = (keyword, callback) -> | |
if typeof window.bing_acctkey != 'undefined' | |
url = "https://api.datamarket.azure.com/Bing/Search/Image?$format=json&Query='#{keyword}'" | |
encoded = btoa "#{window.bing_acctkey}:#{window.bing_acctkey}" # base64エンコード | |
$.ajax | |
url: url | |
type: 'PUT' | |
headers: | |
Authorization: "Basic #{encoded}" | |
dataType: "json" | |
success: (data) -> | |
callback data['d']['results'].map (d) -> | |
d['MediaUrl'] | |
error: (xhr, textStatus, errorThrown) -> | |
alert "Can't perform Bing search ... #{textStatus}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment