retrieve list of all labels in blogger
Asked Answered
D

6

8

Is there a way to use gdata api to retrieve the list of all labels in a blogger?

I need to create a menu based on that list, but cannot simply list all posts and get it, because it is a busy blog and has more than 2000 posts.

Draco answered 15/6, 2012 at 20:25 Comment(0)
D
1

The way I found was using the Blogger's own gadget called Labels. It prints the list of labels and their usage count within some unordered lists(ul) and links(a). You can pull the labels from that after they are loaded using javascript as follows:

$(".list-label-widget-content a").each(function (i, el) {
    var labelText = $(el).text();
    // do what you want with the labels
});

in the end, remove the Labels div element (<div class='widget Label' id='Label1'>)

Draco answered 15/7, 2012 at 21:22 Comment(0)
S
11

Here is the most easy way to get a list of labels by using json call:

<script>
    function cat(json){ //get categories of blog & sort them
        var label = json.feed.category;
        var lst=[];
        for (i=0; i<label.length; i++){
          lst[i] = label[i].term ;  
        }
        alert(lst.sort());  //use any sort if you need that 
    }

</script>

<script src="http://yourblog.blogspot.com/feeds/posts/summary?alt=json&max-results=0&callback=cat"></script>

Just use your blog url.

Sandra answered 21/10, 2012 at 7:6 Comment(1)
For people who just want the list, I used this to make a JSFiddle that returns the tags for any given blog.Petiolate
F
3

Very simple, I give you two ways

  1. With Javascript API First, you must use:

    <script type="text/javascript" src="http://www.google.com/jsapi"></ script> <script type='text/javascript'>
    google.load("gdata", "1.x", { packages : ["blogger"] });
    </script>

    Second, you can use the code below to retrieve the labels

    postRoot.entry.getCategories()[i].getTerm()

    For more tutorials, you can read from http://www.threelas.com/2012/05/how-to-retrieve-posts-using-blogger.html and http://www.threelas.com/2012/04/basic-blogger-javascript-api.html

  2. With JSON with json, if you want to learn how to retrieve the list of labels, use this object

    json.feed.entry[i].category[j].term

    for more detail tutorials, read from http://www.threelas.com/2012/02/basic-blogger-json-feed-api.html and http://www.threelas.com/2012/09/blogger-json-feed-with-jquery-ajax.html

Floc answered 18/10, 2012 at 16:29 Comment(0)
D
1

The way I found was using the Blogger's own gadget called Labels. It prints the list of labels and their usage count within some unordered lists(ul) and links(a). You can pull the labels from that after they are loaded using javascript as follows:

$(".list-label-widget-content a").each(function (i, el) {
    var labelText = $(el).text();
    // do what you want with the labels
});

in the end, remove the Labels div element (<div class='widget Label' id='Label1'>)

Draco answered 15/7, 2012 at 21:22 Comment(0)
A
1

Widget to server the same purpose is provided by bloggers itself.

enter image description here

Widget provides various options like -

  1. You can either show all Labels or choose from your existing List
  2. You can sort the Labels alphabetically or by number of times that label is used (frequency).
  3. You can choose to display these as a List or as a cloud (jumbled).

enter image description here

You can see the same in my blog - Link

Abeyta answered 28/9, 2014 at 6:38 Comment(0)
F
0

I don't see a method to get the list of labels in a blog, but you can retrieve all posts (https://developers.google.com/blogger/docs/2.0/json/reference/posts/list) and check the labels field for each of them: https://developers.google.com/blogger/docs/2.0/json/reference/posts#resource

Frascati answered 15/6, 2012 at 23:16 Comment(2)
As I told in the question, I cannot do it because there's too many posts.Draco
Another problem with this is that Google doesn't let you retrieve all posts through their API. If you try a maxResults parameter of, say, 100, it'll give you an invalidValue error instead. Something like 20 works fine.Broadbent
P
0

First add the JQuery through the following code in console.

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

// ... give time for script to load, then type (or see below for non wait option)

   jQuery.noConflict();

Once you are done with this we can take advantage of the JQuery and get the list of labels

Now what I am doing will work for the Blogger Theme Notable and newly added Theme for blogger.

Normally in these themes you will see Labels in the rights side toogle menu of the page.

So What you need it Click on the Label and Click on Show more.

Now Open Browser Debugging console and declare and variable.

var str = "";

Now run the two codes below

1. $('.first-items .label-name').each(function(){str = str + ", "+($(this).text())})
2. $('.remaining-items .label-name').each(function(){str = str + ", "+($(this).text())})
3. str

all the labels you will be get in comma(;) separated format.

Pinkney answered 21/5, 2017 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.