Search code examples
phpjquerytwitchtwitch-api

Can you get a return URL by GET in JQuery or PHP?


Is it possible to code up a way where the code loads the specific URL and then gets the URL that is returned. For example, when I load this URL https://id.twitch.tv/oauth2/authorize?client_id=8g11d1v5x70s2ql86wyownczj6hfc0&redirect_uri=http%3A%2F%2Flocalhost%2FSocialMediaSite%2FSite%2FHome&response_type=code&scope=user%3Aread%3Aemail&state=b5dcc70324892f0d3987936f9332d811

The URL changes to http://localhost/SocialMediaSite/Site/Home?code=kgegrwigrj5i8mm2vdktwstrbmwivg&scope=user%3Aread%3Aemail&state=742a4bf34bea19022074f92680966cc3

This is because twitch is running the api and giving back the return url as the result to that page. But is there a way to do this automatically? I tried

if($('.LoadStreamers').length){

 $.get('../Admin/TwitchAPI/getFollowers.php',function(data){

    console.log(data);
    $.get(data,function (data2){
        console.log(data2);
    })

 })

}

and the result i get is

  https://id.twitch.tv/oauth2/authorize?client_id=8g11d1v5x70s2ql86wyownczj6hfc0&redirect_uri=http%3A%2F%2Flocalhost%2FSocialMediaSite%2FSite%2FHome&response_type=code&scope=user%3Aread%3Aemail&state=b5dcc70324892f0d3987936f9332d811
 Access to XMLHttpRequest at 'https://www.twitch.tv/login?client_id=8g11d1v5x70s2ql86wyownczj6hfc0&redirect_params=client_id%3D8g11d1v5x70s2ql86wyownczj6hfc0%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%252FSocialMediaSite%252FSite%252FHome%26response_type%3Dcode%26scope%3Duser%253Aread%253Aemail%26state%3Db5dcc70324892f0d3987936f9332d811' (redirected from 'https://id.twitch.tv/oauth2/authorize?client_id=8g11d1v5x70s2ql86wyownczj6hfc0&redirect_uri=http%3A%2F%2Flocalhost%2FSocialMediaSite%2FSite%2FHome&response_type=code&scope=user%3Aread%3Aemail&state=b5dcc70324892f0d3987936f9332d811') 
from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
jquery.min.js:4 GET https://www.twitch.tv/login?client_id=8g11d1v5x70s2ql86wyownczj6hfc0&redirect_params=client_id%3D8g11d1v5x70s2ql86wyownczj6hfc0%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%252FSocialMediaSite%252FSite%252FHome%26response_type%3Dcode%26scope%3Duser%253Aread%253Aemail%26state%3Db5dcc70324892f0d3987936f9332d811 net::ERR_FAILED

Solution

  • Answer for this was that it would be a security issue, so non-conclusive for this. Accepting this as my answer