Hey folks, I wonder if anyone can help me with a cross domain issue I’m having. I’m trying to integrate a Twitch video with JS but I can’t access the API as I get the following error:
Access to fetch at ‘https://api.twitch.tv/api/viewer/token.json’ from origin ‘https:// embed dot twitch dot tv’ (changed domain due to one link in post limit) has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: The value of the ‘Access-Control-Allow-Origin’ header in the response must not be the wildcard ‘*’ when the request’s credentials mode is ‘include’.
Hi sorry for my delay in responding, I viewed the webpage briefly and the stream was working when I viewed, is the error causing any issues or did you resolve it?
Hey Infinity, the stream works fine but the player object comes back as empty and I am unable to interact with it through the script. I’m assuming that this is caused by the errors displayed in the console and is something to do with the cross domain request of the script?
For example I can’t even get the channel name from the player object, and if you check the updated code and the console output you will see it is empty. Using the debugger I can see that the player object although being defined has all empty data:
OK I’ve managed to get to the bottom of this. It appears that although the video starts playing there is a delay in the API being ready to provide data, therefore this can be overcome by putting a delay in or setting a timeout to repeat until data is retrieved. Thanks for your help