Basic Twitch Connect OAuth Help

I haven’t actually tried it on a local server, as long as you have cURL enabled you should be fine. Go into the function and echo a test line to see that you’re getting in there, and then piece it together. So just inside the function do echo "here"; If it echo’s here than you know you’re getting that far. Then the next step would to debug the json to make sure that it’s there. See the lines with the comments next to them and see if it works for ya. If it gives you any errors put them in here. Also it might be a good idea to turn on error reporting just to be sure there aren’t any PHP errors in your script by adding error_reporting(E_ALL); at the top of your script. Hope this leads in the correct direction for you! :smile:

 function get_access_token($code) {

    echo "Here is your code" . $code; // something like this here if it doesn't work than the error is getting into the function and you don't have the $_GET.


	$ch = curl_init($this->base_url . "oauth2/token");
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	$fields = array(
		 'client_id' => $this->client_id,
		 'client_secret' => $this->client_secret,
		 'grant_type' => 'authorization_code',
		 'redirect_uri' => $this->redirect_url,
		 'code' => $code
	);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
	$data = curl_exec($ch);
	$response = json_decode($data, true);

    echo "<pre>".print_r($response,true)."</pre>"; // Place this here and give me the output so then we can figure out what's going on.

	return $response["access_token"];
}