Post by Minecraftndns on Mar 5, 2016 8:08:18 GMT 7
Blogger.com sejatinya mempunyai banyak sekali fungsi dalam menampilkan fitur-fitur tertentu. Kita mungkin terkadang perlu menggunakan widget dan sering kali memiliki kendala yaitu widget yang dibutuhkan tidak tersedia.
Nah dengan masalah seperti itulah Blogger selaku ibu telah menyediakan API untuk bisa mengatasi permasalahan tersebut, sehingga kita terbantu dalam membuat widget dengan cara membaca feed blog yang mempergunakan JSON dan juga JavaScript.
Ada yang belum paham dengan arti JSON itu sendiri? nah saya akan uraikan sedikit perihal tentang JSON tersebut.
Object - (Description)
json.feed.id.$t (Show blog ID)
json.feed.updated.$t (Last update of a blog)
json.feed.category[] (Categories / label array of a blog)
json.feed.category.term (Show the i-th category Blogger)
json.feed.title.$t (Show blog name )
json.feed.subtitle.$t (Show description of a blog )
json.feed.author[] (Array of blog authors )
json.feed.author.name.$t (Show the i-th blog author name )
json.feed.author.uri.$t (Show the i-th profile author uri )
json.feed.openSearch$totalResults.$t (Show total posts )
json.feed.entry[] (Posts array of a blog)
json.feed.entry.id.$t (Show the i-th post ID )
json.feed.entry.title.$t (Show the i-th post title )
json.feed.entry.published.$t (Show time published of the i-th post )
json.feed.entry.updated.$t (Show when the i-th post is updated )
json.feed.entry.category[] (Show array of post categories)
json.feed.entry.category[x].term (Show the x-th category of the i-th post )
json.feed.entry.summary.$t (Show post summary )
json.feed.entry.content.$t (Show post content )
json.feed.entry.link[] (Links array of a post
json.feed.entry.link[x].href (Show the x-th link of the i-th post )
json.feed.entry.author[] (Array of post authors)
json.feed.entry.author[x].name.$t (Name of the x-th author on the i-th post)
json.feed.entry.author[x].uri.$t (Show uri author profile)
json.feed.entry.author[x].gd$image.src (Image uri of the x-th author profile on the i-th post)
json.feed.entry.media$thumbnail.url (Show image on the i-th post)
json.feed.entry.thr$total.$t (Show total threaded comments)
json.feed.id.$t (Show blog ID)
json.feed.updated.$t (Last update of a blog)
json.feed.category[] (Categories / label array of a blog)
json.feed.category.term (Show the i-th category Blogger)
json.feed.title.$t (Show blog name )
json.feed.subtitle.$t (Show description of a blog )
json.feed.author[] (Array of blog authors )
json.feed.author.name.$t (Show the i-th blog author name )
json.feed.author.uri.$t (Show the i-th profile author uri )
json.feed.openSearch$totalResults.$t (Show total posts )
json.feed.entry[] (Posts array of a blog)
json.feed.entry.id.$t (Show the i-th post ID )
json.feed.entry.title.$t (Show the i-th post title )
json.feed.entry.published.$t (Show time published of the i-th post )
json.feed.entry.updated.$t (Show when the i-th post is updated )
json.feed.entry.category[] (Show array of post categories)
json.feed.entry.category[x].term (Show the x-th category of the i-th post )
json.feed.entry.summary.$t (Show post summary )
json.feed.entry.content.$t (Show post content )
json.feed.entry.link[] (Links array of a post
json.feed.entry.link[x].href (Show the x-th link of the i-th post )
json.feed.entry.author[] (Array of post authors)
json.feed.entry.author[x].name.$t (Name of the x-th author on the i-th post)
json.feed.entry.author[x].uri.$t (Show uri author profile)
json.feed.entry.author[x].gd$image.src (Image uri of the x-th author profile on the i-th post)
json.feed.entry.media$thumbnail.url (Show image on the i-th post)
json.feed.entry.thr$total.$t (Show total threaded comments)
Berikut adalah contoh yang teramat sederhana dari kode yang saya lampirkan diatas tersebut :
JSON atau sering kali dibaca Jason adalah singkatan dari JavaScript Object Notation (Notasi Objek JavaScript), yang artinya adalah Format ringkas pertukaran data komputer.
Berikut ini saya akan lampirkan beberapa Kode Blogger JSON Feed API :
Semisal saya hanya memerlukan 5 buah postingan terbaru yang berdasarkan label yang telah saya pilih, misalnya "Hiburan" dan saya hanya mengambil ringkasan pos dan juga judul.
<script type="text/javascript">
function mycallback(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
for (var j = 0; j < json.feed.entry.link.length; j++) {
if (json.feed.entry.link[j].rel == 'alternate') {
var postUrl = json.feed.entry.link[j].href;
break;
}
}
var postTitle = json.feed.entry.title.$t;
var postSummary = json.feed.entry.summary.$t;
var item = '<div class="wrapper"><h3><a href=' + postUrl + '>' + postTitle + '</h3></a><p>' + postSummary + '</p></div>';
document.write(item);
}
}
</script>
<script src="http://nama.blogspot.com/feeds/posts/summary/-/Blogger?max-results=5&alt=json-in-script&callback=mycallback"></script>
function mycallback(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
for (var j = 0; j < json.feed.entry.link.length; j++) {
if (json.feed.entry.link[j].rel == 'alternate') {
var postUrl = json.feed.entry.link[j].href;
break;
}
}
var postTitle = json.feed.entry.title.$t;
var postSummary = json.feed.entry.summary.$t;
var item = '<div class="wrapper"><h3><a href=' + postUrl + '>' + postTitle + '</h3></a><p>' + postSummary + '</p></div>';
document.write(item);
}
}
</script>
<script src="http://nama.blogspot.com/feeds/posts/summary/-/Blogger?max-results=5&alt=json-in-script&callback=mycallback"></script>
Nah dengan penerapan yang sedemikian rupa maka akan didapatkan hasil yang kalian inginkan, kode JSON tersebut hanya akan bekerja apabila digabungkan dengan Javascript.
Sumber : fredi-yana.blogspot.co.id/2016/03/kode-blogger-json-feed-api.html