Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!empty($_GET)) {
- $url = "https://api.twitch.tv/kraken/oauth2/token";
- $data = Array(
- "client_id" => "#",
- "client_secret" => "#",
- "grant_type" => "authorization_code",
- "redirect_uri" => "http://localhost/twitchTest",
- "code" => $_GET['code'],
- "state" => ""
- );
- $data_string = "";
- foreach ($data as $key => $value) {
- $data_string .= $key . '=' . $value . '&';
- }
- $data_string = substr_replace($data_string, '', -1);
- try {
- $ch = curl_init();
- if ($ch === false) {
- throw new Exception("Failed to initialize");
- }
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, count($data));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($ch);
- if ($result === false) {
- throw new Exception(curl_error($ch), curl_errno($ch));
- }
- curl_close($ch);
- var_dump($result);
- $gebruiker = json_decode($result, true);
- var_dump($gebruiker);
- } catch (Exception $e) {
- trigger_error(sprintf("Curl failed with error #%d: %s", $e->getCode(), $e->getMessage()), E_USER_ERROR);
- }
- }
Add Comment
Please, Sign In to add comment