PHP code example of turanct / showpad-api

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

    

turanct / showpad-api example snippets




// Create a config object
$config = new Showpad\ConfigBasic(SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, null, null);

// Create a client object
$guzzleClient = new Guzzle\Http\Client();
$client = new Showpad\GuzzleAdapter($guzzleClient);

// Create an Authentication object, using the config
$auth = new Showpad\Authentication($config, $client);

// Get the url for the first step of the OAuth2 process
$authorizeUrl = $auth->authenticationStart(SHOWPAD_AUTH_REDIRECT_URL);

// You should now redirect your user to this url, and let him authorize the application.
// If they authorized the application, you'll get a GET parameter 'code', which you'll need for step 2.



// Create a config object
$config = new Showpad\ConfigBasic(SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, null, null);

// Create a client object
$guzzleClient = new Guzzle\Http\Client();
$client = new Showpad\GuzzleAdapter($guzzleClient);

// Create an Authentication object, using the config
$auth = new Showpad\Authentication($config, $client);

// Get the OAuth2 tokens using the code from the first step of the OAuth2 process
$tokens = $auth->authenticationFinish($codeFromFirstStep, SHOWPAD_AUTH_REDIRECT_URL);

// If everything went ok, $tokens is now an associative array with keys 'access_token' and 'refresh_token'
// You should store these keys to be able to do requests in the future.



// Create a config object
$config = new Showpad\ConfigBasic(
	SHOWPAD_URL,
	SHOWPAD_APP_ID,
	SHOWPAD_APP_SECRET,
	$tokens['access_token'],
	$tokens['refresh_token']
);

// Create a client object
$guzzleClient = new Guzzle\Http\Client();
$client = new Showpad\GuzzleAdapter($guzzleClient);

// Create an Authentication object, using the config
$auth = new Showpad\Authentication($config, $client);

// Request new tokens
$tokens = $auth->refreshTokens();

// If everything went ok, $tokens is now an associative array with the keys 'access_token' and 'refresh_token',
// containing fresh tokens. You should store these keys to be able to do requests in the future.



// Create a config object
$config = new Showpad\ConfigBasic(
	SHOWPAD_URL,
	SHOWPAD_APP_ID,
	SHOWPAD_APP_SECRET,
	$tokens['access_token'],
	$tokens['refresh_token']
);

// Create a client object
$guzzleClient = new Guzzle\Http\Client();
$client = new Showpad\GuzzleAdapter($guzzleClient);

// Create an Authentication object, using the config
$auth = new Showpad\Authentication($config, $client);

// Create a showpad client. This client contains all possible api methods.
$client = new Showpad\Client($auth);

// You can now e.g. upload a file to showpad:
$client->assetsAdd($pathToFile);