PHP code example of compwright / oauth2-servicetitan

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

    

compwright / oauth2-servicetitan example snippets


$factory = new Compwright\OAuth2\Servicetitan\ServicetitanProviderFactory();
$provider = $factory->new(
    clientId: null,     // optional, recommended to pass as an option to getAccessToken()
    clientSecret: null, // optional, recommended to pass as an option to getAccessToken()
    sandbox: false,     // enable for sandbox environment
    enterprise: false   // enable for Enterprise Hub clients
);

// Get an access token using the authorization code grant
$token = $provider->getAccessToken('client_credentials', [
    'client_id'     => '{servicetitan-client-id}',
    'client_secret' => '{servicetitan-client-secret}',

    //