Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. using fetch(url) to get xml (youtube feed)

using fetch(url) to get xml (youtube feed)

Scheduled Pinned Locked Moved JavaScript
helpjavascriptphpcomlinux
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DSB Audio David Sweeney Bear
    wrote on last edited by
    #1

    I'd like to be able to fetch data from my youtube channel's rss feed to display dynamic content on my website... So, I have my youtube channel rss feed address, something like: https://www.youtube.com/feeds/videos.xml?channel\_id=n0tMyRealcHaNNel1D I'm able to us wget in bash to download the data into a file, and obviously I can load the xml in my browser, but am getting stuck fetching the data in js.

    fetch("https://www.youtube.com/feeds/videos.xml?channel\_id=n0tMyRealcHaNNel1D")
    .then(response => response.text())
    .then(data => {
    const parser = new DOMParser();
    const xml = parser.parseFromString(data, "application/xml");
    console.log(xml);
    })
    .catch(console.error);

    gives me:

    Access to fetch at 'https://www.youtube.com/feeds/videos.xml?channel\_id=n0tMyRealcHaNNel1D' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    custom.js:3 GET https://www.youtube.com/feeds/videos.xml?channel\_id=n0tMyRealcHaNNel1D net::ERR_FAILED 200
    (anonymous) @ custom.js:3
    TypeError: Failed to fetch
    at custom.js:3:1

    having looked into this further, I discovered this: [https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9\](https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9) so I tried prepending the proxy [https://cors-anywhere.herokuapp.com/\](https://cors-anywhere.herokuapp.com/) to the fetch url. Now I get:

    custom.js:3 GET https://cors-anywhere.herokuapp.com/https://www.youtube.com/feeds/videos.xml?channel\_id=n0tMyRealcHaNNel1D 403 (Forbidden)

    So no joy there. The final option mentioned in the medium article above is to create a proxy for myself... but before heading down that road (especially if it's going to be a waste of time!), I thought i'd ask here in case anyone has any advice for me. Maybe I'm barking up the wrong tree and need to use google API and php? (a daunting prospect for me!)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups