PHP code example of depotwarehouse / oauth2-twitch

1. Go to this page and download the library: Download depotwarehouse/oauth2-twitch 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/ */

    

depotwarehouse / oauth2-twitch example snippets


$provider = new \Depotwarehouse\OAuth2\Client\Twitch\Provider\Twitch([
    'clientId' => "YOUR_CLIENT_ID",
    'clientSecret' => "YOUR_CLIENT_SECRET",
    'redirectUri' => "http://your-redirect-uri"
]);

if (isset($_GET['code']) && $_GET['code']) {
    $token = $this->provider->getAccessToken("authorization_code", [
        'code' => $_GET['code']
    ]);

    // Returns an instance of Depotwarehouse\OAuth2\Client\Twitch\Entity\TwitchUser
    $user = $this->provider->getResourceOwner($token);
    
    $user->getDisplayName();
    $user->getId()
    $user->getType();
    $user->getBio();
    $user->getEmail();
    $user->getPartnered();
bash
cd test/
php -S localhost:8000