PHP code example of ova777 / tsoauth

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

    

ova777 / tsoauth example snippets


use ova777\TSOAuth;

$tsoauth = TSOAuth\Core::create(array(
    'auto_refresh_token' => true,
    'id' => 'OAUTH_CLIENT_ID',
    'secret' => 'OAUTH_CLIENT_SECRET',
    'host' => 'https://tronsalt.ru',
    'access_token' => '', //If exists
    'refresh_token' => '', //If exists
    'scope' => array('user.data'), //Required permissions
));

$tsoauth->goAuthorizationCode();

if(isset($_GET['error'])) { 

try {
    $tsoauth->getAccessTokenByCode($_GET['code']);
    //Save $tsoauth->access_token and $tsoauth->refresh_token for this User
} catch (TSOAuth\Except $error) {
    echo $error->asString();
}

try {
    $transaction = $tsoauth->makeTransaction('500'); //Sum
    if(isset($transaction['actions'])) {
        $commit = $tsoauth->endTransaction($transaction['actions']['commit']);
        //print_r($commit);
    }
} catch (TSOAuth\Except $error) {
    echo $error->asString();
}