I have a blog on google (blogger) and i want to get json data from external website in order to integrate into my posts. I used jquery library and getJson function in order to retrieve the json data but nothing is returned.
Blogger restrict any jquery external calls ? Have any idea? Thank you
You can, check out http://code.google.com/apis/gdata/docs/json.html for information. But, look at the JSONP mode used by jquery and you'll see how to do it. For example, the following code shows how to get a comment feed from the Blogger API:
var BloggerImporter = {
getComments : function(username){
var feedURL = "http://"+username+".blogspot.com/feeds/comments/default";
var paras = {
alt : 'json-in-script'
};
$.ajax({
url: feedURL,
type: 'get',
dataType: "jsonp",
success: BloggerImporter.onGotCommentData,
data: paras
});
},
/**
* Parse the JSON comment data returned by the Google Blogger API
*/
onGotCommentData : function(data){
var feed = data.feed;
var entries = feed.entry || [];
var txt = "";
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
var title = entry.title.$t;
txt += title;
}
alert(txt);
}
}
Here is the code I use to inline my entire blog. Not good for SEO as google will never see it, but all I really cared about was making the blog page look half decent.
<div id="blogContainer"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.ajax({
url: 'http://www.blogger.com/feeds/<your blogger ID>/posts/default?alt=json-in-script',
type: 'get',
dataType: "jsonp",
success: function(data){
for (var i = 0; i < data.feed.entry.length; i++){
$('#blogContainer').append('<div class="blogItem"><h2>'
+ data.feed.entry[i].title.$t + '<span class="author"> by '
+ data.feed.entry[i].author[0].email.$t + '</span></h2>'
+ data.feed.entry[i].content.$t
+ '<br clear="all"></div>');
}
}
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With