PHP code example of michaelgarrez / twitch-alerts-sdk

1. Go to this page and download the library: Download michaelgarrez/twitch-alerts-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelgarrez / twitch-alerts-sdk example snippets




$client = new Client($clientId, $clientSecret, $redirectUri); // $redirectUri should also match exactly the data you entered when you registred your application



$client = new Client($clientId, $clientSecret, $redirectUri);
$redirectUrl = $client->getAuthorizeUrl(['donations.create']); // You can pass multiple scopes here

// You should then need to redirect the user to this URI.
// When the user will return to your redirect_uri either the "code" parameter will be present on the query parameters (you will need it for the next step) or an "error" parameter will be present which means the user refused to allow your application to access his account.


$client = new Client($clientId, $clientSecret, $redirectUri);
$tokens = $client->getAccessToken($code); // $code is the code returned on the previous step

// $tokens will contains multiple keys : "access_token" and "refresh_token".


$client = new Client($clientId, $clientSecret, $redirectUri);
$tokens = $client->refreshAccessToken($refreshToken); // $refreshToken is the refreshToken you got from the previous step (or the last refreshAccessToken you did).

// $tokens will contains multiple keys : "access_token" and "refresh_token".