Oct 17, 2016

How to get blogger all posts?

In order to get blogger all posts, I really don't wanna use Blogger API. Because I am front-end developer and I don't wanna create Blogger API key and store them in Javascript files.

I found a simple & very fast solution.
We just make a jsonp request to

http://{your-domain}.blogspot.com/feeds/posts/default?max-results=500&alt=json-in-script&callback={your-js-callback}

Our example AngularJs:

var url = "http://blogtruyentm.blogspot.com/feeds/posts/default?max-results=500&alt=json-in-script&callback=JSON_CALLBACK";
$http.jsonp(url)
    .success(function(data) {
        console.log(angular.toJson(data.feed.entry));
        $scope.entries = data.feed.entry.map(function(item) {
            var _url;
            var _title;
            item.link.forEach(function(item) {
                if (item.rel = "alternative" && item.type == "text/html") {
                    _url = item.href;
                    _title = item.title;
                }
            });
            return {
                title: _title,
                url: _url
            };
        });
    })
    .error(function(data) {
        console.log("An error occurs while getting posts from blogger");
    });
Angular $http JSONP reference here.

Found a related stackoverflow topic: here

No comments:

Post a Comment