I would like to use tag1216's program on page to collect tags for new bookmarks, display them in Force layout, and link nodes to articles.
However, if you try to use the API of the bookmark, cross-origin requests will be blocked and you will not be able to do the same as the API of qiita.
Does this mean that qiita's API returns a response as JSONP, so it doesn't get stuck in a cross domain?
If it is JSONP, will it not be restricted?
In that case, how can I return it with JSONP using Tena Bookmark API?
I'm sorry to ask so many questions about ignorance.Thank you for your help.
The API mentioned in the question explains how to retrieve it in JSONP.
Also, get the following query parameters for http://b.hatena.ne.jp/entry/json/
:
You can retrieve JSON data enclosed by the callback function by JSONP by sending it in a request.
(abbreviated below)
If you don't know how to use JSONP, you should try and narrow it down to where you stumble and ask questions again.
The following is an example of obtaining bookmarks for this site in the high-speed version (/entry/jsonlite/
):
<div><p>Hatena Bookmarks:</p>
<pred="hatena_bkm">/pre>
</div>
<script>
"use strict";
function my_hatena_bkm_callback(bkm_json){
document.getElementById("hatena_bkm").textContent=
JSON.stringify(bkm_json, undefined, 2);
}
</script>
<script src="http://b.hatena.ne.jp/entry/jsonlite/?url=http%3A%2F%2Fja.stackoverflow.com%2F&callback=my_hatena_bkm_callback"></script>
"However, what I want to do seems to be ""collecting tags for new articles."""
From a quick look at the list of bookmark documents, there seems to be no API to retrieve it. What do you think?
I think there is a way to create your own API using the RSS (or scraping etc.) provided by Hatena, but this is a different story.
JSONP is a JSON that can be read as an external script, which is different from the usual JSON format.Therefore, the API provider needs to take action, but neither Qiita nor Hatena bookmarks are compatible.
Note: The appropriate API for Hatena bookmarks can be retrieved by JSONP by adding the callback parameter (see mjy's answer.
The response from Qiita on the demo site mentioned above has the following headers:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Origin: http://bl.ocks.org
Access-Control-Expose-Headers:
Access-Control-Max-Age: 1728000
This is a group of headers defined in Cross-Origin Resource Sharing (CORS) that are used for access control.The XMLHttpRequest used for Ajax communication, including d3.js, applies the rule Same-Origin Policy and basically cannot communicate between different origin, but only if permitted by these header groups.http://bl.ocks.org
is allowed.
On the other hand, the Tena Bookmark API does not print these headers, so the browser interprets them as "rejects all requests from different origin" and blocks communication.
Other references
There is a way to bite a site that allows cross-domain communication such as JSONProxy or allow-any-origin.appspot.com.
var url="http://b.hatena.ne.jp/entry/json/http://www.hatena.ne.jp/";
varproxy_url="http://allow-any-origin.appspot.com/"+encodeURIComponent(url);
d3.json(proxy_url, function(error,json){
if(error){
return console.warn(error);
}
$("#data").text(JSON.stringify({
title —json.title,
url —json.url,
count —json.count
}));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">/script><script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js">/script>
<h1>Hatena Bookmarks</h1>
<pred="data"></pre>
These sites are basically unguaranteed, but they are useful if you want to create something that works.
If necessary, you can create your own API return page and replace it later.
© 2024 OneMinuteCode. All rights reserved.