Home > Enterprise >  Push data from console.log to html
Push data from console.log to html

Time:05-21

const access_token = ""


fetch('https://api.fitbit.com/1/user/-/profile.json', {
    method: "GET",
    headers: {"Authorization": "Bearer "   access_token}
})
.then(response => response.json())
//.then(json => console.log(json))
.then((out) =>
{ 
   
    console.log(out.data);
    document.getElementById('log').innerHTML=out.data;
    
})

hi, I have been trying to fetch wep API using the above js code. i have successfully fetched the data inside my debug console but after modify it to fetch inside HTML, shows undefined. Can someone help me. For security purpose i removed the access token.

CodePudding user response:

You code seems OK. Either your access token is not correct, or the JSON object you receive has no "data" key.

If I'm on the right page, it seems that you should use "out.user" instead of "out.data": https://dev.fitbit.com/build/reference/web-api/user/get-profile/

CodePudding user response:

make sure the out.data is string not an array or object.

  • Related