Search code examples
javascriptbloggergoogle-api-js-client

how to access data from simple link with api key through http request


I have this simple link https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key

It works fine and give me this

{
  "kind": "blogger#blog",
  "id": "##############",
  "name": "blog-blogger",
  "description": "",
  "published": "2022-02-08T08:38:50-08:00",
  "updated": "2022-02-22T16:52:43-08:00",
  "url": "http://original-1-1.blogspot.com/",
  "selfLink":
  "posts": {
    "totalItems": 1
  },
  "pages": {
    "totalItems": 0
  },
  "locale": {
    "language": "en",
    "country": "?",
    "variant": ""
  }
}

now how i fetch above data using javascript

like

l = fetch(https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key);
q = l.json();
console.log(q.kind);

Solution

  • This will get you kind

    const xhttp = new XMLHttpRequest();
    xhttp.onload = function() {
        let responseJSON = JSON.parse(this.responseText);
            console.log(responseJSON.kind);
    }
    xhttp.open("GET", "https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key", true);
    xhttp.send();