Tengo este enlace simple https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key
Funciona bien y dame esto
{ "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": "" } }ahora cómo obtengo los datos anteriores usando javascript
me gusta
l = fetch(https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key); q = l.json(); console.log(q.kind);Estoy trabajando en algo similar, este es el código que estoy usando.
var request = new XMLHttpRequest() // Open a new connection, using the GET request on the URL endpoint request.open('GET', `https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key`, true) request.onload = function () { // Begin accessing JSON data here var data = JSON.parse(this.response) console.log(data) }Otra opción es usar fetch como sugeriste
function getData() { const response = await fetch('https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key') const data = await response.json() }Este es el sitio web del que obtuve mi información: https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/
¡Espero que esto responda a su pregunta!
señor
Esto te hará 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();// declara una variable para contener la URL de tu API como esta const url = " https://www.googleapis.com/blogger/v3/blogs/my-ID?key=Api_key"
// the spelling of your fetch is incorrect. You can use thisfetch(url) .then(response => response.json()) .then(data => console.log(data));
// Esto debería funcionar
// Usando su clave API Asegúrese de pasar su clave API a la llamada API REST como un parámetro de consulta reemplazando API_KEY con su clave API,