Please note: I don't have a background in programming.
I'm making an effort to learn as much as possible.
As I was reading (and later experimenting with) the solution to this query, it dawned on me that having the same information in JSON format could be quite helpful. Specifically, how does one fetch the "home" URL of a Blogger blog using JSON.
I attempted to work it out myself, especially considering that...
<script type="text/javascript>
function specialpost(json) {
document.write('<div>');
// VARIABLE DECLARATION
var i;
var j;
// LOOP
for (i = 0; i < json.feed.entry.length; i++)
{
for (j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel == 'alternate') {
break;
}
}
var postUrl = "'" + json.feed.entry[i].link[j].href + "'";
var postTitle = json.feed.entry[i].title.$t;
var postContent = json.feed.entry[i].content.$t;
var item = '<h3><a href="' + postUrl + '" target="_blank">' + postTitle + '</a></h3><p>' + postContent + '</p>';
document.write(item);
}
document.write('</div>');
}
</script>
<script src="https://MYBLOG.blogspot.com/feeds/posts/default/-/special?max-results=NUMBER_OF_POSTS_DISPLAYED&alt=json-in-script&callback=specialpost"></script>
...the code will generate a div
with titles (including links) and content of specified posts labeled "special". However, halfway through my attempt, things got a bit confusing.
I am using jsonviewer to analyze my blog's JSON data in a structured tree-like manner. I suspect that if each post's URL is within [] entry
, then the blog's URL might be located within [] link
.
Question: Is this assumption correct?
[] link
has four entries: {}0
,{}1
,{}2
, and {}3
each containing three sub-entries:
rel
set to
,"http://schemas.google.com/g/2005#feed"
"self"
,"alternate"
, and"hub"
respectivelytype
defined as"application/atom+xml"
for first two,text/html
for the third
- undefined for{}3
href
set to:
"http://MYBLOG.blogspot.com/feeds/posts/default"
(followed by?alt=json
leading back to the JSON tree view).
"https://www.blogger.com/feed/1234567890123456789/posts/default?alt=json"
(19-digit number assigned by Google)
"http://MYBLOG.blogspot.com"
and
respectively."http://pubsubhubbub.appspot.com"
I believe {}2
holds what I need.
Question: Am I correct again? If so, how do I assign the value of var myblogUrl
to the href
from {}2
?
Lastly: What are the other three entries for? The href
in {}0
seems to direct to a subscription page. Is this accurate?