Johnny Everson
Johnny Everson

Reputation: 8601

Retrieve posts based on Labels in blogger using Gdata

Is it possible to use gdata javascript or any other javascript api to retrieve the list of blog posts based on labels?

My usage case:

Each blog post has a label that means its category. Some posts are labelled with 'Summary' and the category it belongs.

I want to be able to display the summary of MyCategory(Label) on the label's page. e.g. http://myblog.blogspot.com/search/label/MyCategory

Is it possible to retrieve the list of blog posts matching 'Summary' and 'MyCategory'?

UPDATE:

more details:

Upvotes: 4

Views: 1937

Answers (1)

GitaarLAB
GitaarLAB

Reputation: 14645

I've read and re-read this question and blogspot-link a couple of times. It's difficult to understand.

I think it would help if you gave some more information:

  • where do you want to place this javascript? I mean: is it going to be placed on the same blog? I'm asking because this determines cross-site security requirements.
  • I have a strong feeling this is actually a question where you want to a cross-domain request (load data from a different domain|server (blogspot.com)) that you do not control, otherwise you'd be playing with 'Access-Control-Allow-Origin' on the server-side.
  • Will this script be located in a online or local (x)html source?
  • Could you please provide a more elaborate example (or sample) of an existing list that contain's this labels, or do you want to crawl a blog like a spider|index-robot?

If the above assumptions are correct, the first part of your problem is retrieving cross-domain data (which is hard nowadays using simple solutions like XMLHttpRequest aka AJAX).
You could then start looking at some own server-side scripts (php) to get this data and send it (pre-parsed) to your browser-application (effectively this is simply a proxy located on your own domain).
I have also heard of using a java-object (or silverlight? or flash which nowadays also suffers from cross-domain-security restrictions), to get around this modern day cross-domain security.
You could then embed one or more of these objects (that retrieve the source) and communicate with them through javascript. A variation of this technique is also often used for cross-browser multiple file-uploads.
There is a big chance there is already a solution (object) to this part of your problem here on StackOverflow.

If you fix this first part of the problem, the second part of your problem simply comes down to parsing (regex for example) your retrieved 'label'-data, building new links from them to retrieve the 'summary'-content you where after, using the same data-retrieval technique that was used to get the labels-list in the first place..

Is this what you are after?

UPDATE: In pure javascript/json there is an excellent topic here on SO.
Should you go with java, you could look at this.
In php you use file_get_contents() or file_get_html(). See also this topic on SO.

UPDATE2: The accepted ANSWER (out of comment's below:)
On google's developers blogger docs 2.0 you can find: RetrievingWithQuery.
Quote:

/category
   Specifies categories (also known as labels) to filter the feed results. For example, blogger.com/feeds/blogID/posts/default/-/Fritz/Laurie returns entries with both the labels Fritz and Laurie.

You can also find a working piece of javascript that uses this technique over here: list-recent-posts-by-label

Now you can simply continue 'AJAX'ing your summary's out of this filtered list.

Good luck!

Upvotes: 1

Related Questions