Hey guys. So I have been trying to write an application using New Twitch API using PHP and I got stuck at the first step which is authentication. I have read through various blogs and API references and now I know, that I need to use “Authorization code flow” to obtain user access token for my needs.
I am having problem with redirection and the Twitch auth. Below you can see my code snippet. In the end, I would like to get instantly redirected to obtained link via cURL where I can login with twitch credentials and then get redirected back to localhost.
This snippet shows clickable text on my website, on which when I click, I am redirected to Twitch and can login. So this is exactly what I want. But! I don’t want clickable button, I want to follow the URL from cURL post, so when I have added this line I though it would work:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
But unfortunately it doesn’t work, and I stay on my localhost as nothing happened. I tried also different ways, such as cURLing again the obtained href from the response before, but it also doesn’t work.
Ok, I have solved this issues. Problem was http://localhost:8000/ and http://localhost:8000.
As of now I am having different problem with your code. I am getting An Error Occured at code for token exchange: because at lines 55 in index.php, for some reason the return http_code is 0.
That means theres something super wrong on your server, and it’s ability to make HTTP requests
Expand the code to spit out more information about the error.
Line 55 is blank?
Line line 80 $error = 'An Error Occured at code for token exchange: ' . print_r($r, true); you probably want to update, to dump out the whole $i object and trace the issue.
HTTP Code 0 can be “failed to find the server” or other issue
I tried to print out the the $i variable from line 52. This is the output. I guess something is wrong with my PHP7 installation, will try it on XAMPP server instead…
It’s also possible that the Server provider that you are using is blocking outbound requests.
Could also be the firewall.
It could also be the SSL Cert bundles being out of date.
But trying cURL on the command line may help track that one down.