freebase 网站上的示例
http://wiki.freebase.com/wiki/MQL_Manual_Javascript_Example
使用http://api.freebase.com/api/service/mqlread
<script>
function listAlbums(band) { // Display albums by the specified band.
var envelope = { // The mqlread query envelope
query : { // The MQL query
type: "/music/artist", // Find a band
name: band, // With the specified name
album: [{ // We want to know about albums
name:null, // Return album names
release_date:null, // And release dates
sort: "release_date", // Order by release date
"release_type!=":"single" // Don't include singles
}]
}
};
var output = $("#output"); // Output goes here
output.html("<h1>Albums by " + band + "</h1>"); // Display a title
// Invoke mqlread and call the function below when it is done.
// Adding callback=? to the URL makes jQuery do JSONP instead of XHR.
jQuery.getJSON("http://api.freebase.com/api/service/mqlread?callback=?",
{query: JSON.stringify(envelope)}, // URL parameters
displayResults); // Callback function
// This function is invoked when we get the result of our MQL query
function displayResults(response) {
if (response.code == "/api/status/ok" &&
response.result && response.result.album) { // Check for success...
var list = $("<ul>"); // Make <ul> tag.
output.append(list.hide()) // Keep it hidden
var albums = response.result.album; // Get albums.
jQuery.each(albums, function() { // Loop through albums.
list.append($("<li>").html(this.name)); // Make <li> for each.
});
list.show("normal"); // Reveal the list
}
else { // On failure...
output.append("Unknown band: " + band); // Display message.
}
}
}
</script>
这显然已被弃用;是否有使用新的https://www.googleapis.com/freebase/v1/mqlread API 的代码示例?似乎在网上找不到太多(我仍在学习绳索)。