MORE HELP FOR PHP NEWBIES
I know this is an old topic but it’s the only one with an actual code example that I was looking for. I didn’t realize it’s the same one in xxplosions example until after I started playing with it. There is one very important piece of information missing in the above example though. Simply add this to the very end of xxplosions https://github.com/Xxplosions/twitchtv-oauth script and you’ll get a really quick example of a full authorization (from you to twitch) and uri redirect (from twitch back to you).
$twitchtv = new TwitchTV();
echo '<a href="'.$twitchtv->authenticate().'">Authenticate Me</a>';
echo "<br/>";
$twitchtv = new TwitchTV();
$ttv_code = $_GET['code'];
$access_token = $twitchtv->get_access_token($ttv_code);
$user_name = $twitchtv->authenticated_user($access_token);
echo 'Thank you '.$user_name.'! Authentication Completed!';
You can rename the twitchtv.php file to whatever you’d like and include or require it from wherever you want.
For example: rename it to auth.php then include it from your index.php
If you have index.php set as your twitch client redirect uri it will still work.
The page you trigger the link from doesn’t matter. As long as the redirect uri in the script and on the twitch site are listed as the same then the script will work.
There is still a TON more work ahead of you. The class provided by xxplosions is only filled with helper functions. Unfortunately there isn’t a list of real world examples how to call each and every function in his class. I think that would have been nice.
Here’s a super easy barebones way to do a test authorization of your developer client (program/bot) using a link.
echo '<a href="https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=YOURCLIENTID&redirect_uri=YOURCLIENTURL.php&scope=chat_login">Authorize Me</a><br/>';
Replace YOURCLIENTID AND YOURCLIENTURL appropriately.
I’ve tested each example I’ve listed here and can assure their accuracy (until twitch decides to change everything again and again). Xxplosions class attempts to be easier to learn than IBurn36360’s but still has less than stellar examples. It does work and is certainly a heck of a lot easier than dealing with IBurn36360’s class for those new to PHP. I just started working with this stuff a few days ago. If anyone has comments/suggestions on helping to build a twitch web interface and chat moderation bot I’m all ears.