从我的 Tumblr 获取帖子 API
Get posts from my Tumblr API
我需要通过 api 获取我的 tumblr 帖子。
我已经成功设置了 api 密钥。
我正在为此使用 Angular2,打字稿。
我正在使用 jsonp,这样我就不会遇到跨源问题。
这是我目前的尝试:
var config = {
params: {
action: "query",
prop: "revisions",
format: "json",
callback: "JSON_CALLBACK"
}
}
var url = "https://api.tumblr.com/v2/blog/thepoolcover.tumblr.com/posts?api_key=lqoK2G4BT9X8xnewyW0l45ky4aTKWTqQ3PzF14gefIglpIRnBz";
this.jsonp.request(url, config).subscribe(response => {
console.log(response);
});
我没有收到打字稿编译器错误,但是,我确实收到浏览器异常控制台错误:
您应该使用 JSONP_CALLBACK
作为回调名称而不是 JSON_CALLBACK
和 URLSeachParams 作为查询参数:
URLSearchParams search = new URLSearchParams();
search.set('action', 'query');
search.set('prop', 'revisions');
search.set('format', 'json');
search.set('callback', 'JSONP_CALLBACK');
var config = {
search: search
};
var url = "https://api.tumblr.com/v2/blog/thepoolcover.tumblr.com/posts?api_key=lqoK2G4BT9X8xnewyW0l45ky4aTKWTqQ3PzF14gefIglpIRnBz";
jsonp.request(url, config).subscribe(response => {
console.log(response);
});
这里是对应的plunkr:
我需要通过 api 获取我的 tumblr 帖子。
我已经成功设置了 api 密钥。 我正在为此使用 Angular2,打字稿。
我正在使用 jsonp,这样我就不会遇到跨源问题。
这是我目前的尝试:
var config = {
params: {
action: "query",
prop: "revisions",
format: "json",
callback: "JSON_CALLBACK"
}
}
var url = "https://api.tumblr.com/v2/blog/thepoolcover.tumblr.com/posts?api_key=lqoK2G4BT9X8xnewyW0l45ky4aTKWTqQ3PzF14gefIglpIRnBz";
this.jsonp.request(url, config).subscribe(response => {
console.log(response);
});
我没有收到打字稿编译器错误,但是,我确实收到浏览器异常控制台错误:
您应该使用 JSONP_CALLBACK
作为回调名称而不是 JSON_CALLBACK
和 URLSeachParams 作为查询参数:
URLSearchParams search = new URLSearchParams();
search.set('action', 'query');
search.set('prop', 'revisions');
search.set('format', 'json');
search.set('callback', 'JSONP_CALLBACK');
var config = {
search: search
};
var url = "https://api.tumblr.com/v2/blog/thepoolcover.tumblr.com/posts?api_key=lqoK2G4BT9X8xnewyW0l45ky4aTKWTqQ3PzF14gefIglpIRnBz";
jsonp.request(url, config).subscribe(response => {
console.log(response);
});
这里是对应的plunkr: