PHP code example of xeroapi / xero-php-oauth2-app

1. Go to this page and download the library: Download xeroapi/xero-php-oauth2-app 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/ */

    

xeroapi / xero-php-oauth2-app example snippets


// This library will read variable from the .env file.
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$clientId = getenv('CLIENT_ID');
$clientSecret = getenv('CLIENT_SECRET');
$redirectUri = getenv('REDIRECT_URI');

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
	'clientId'                => $clientId,   
	'clientSecret'            => $clientSecret,
	'redirectUri'             => $redirectUri,
	'urlAuthorize'            => 'https://login.xero.com/identity/connect/authorize',
	'urlAccessToken'          => 'https://identity.xero.com/connect/token',
	'urlResourceOwnerDetails' => 'https://api.xero.com/api.xro/2.0/Organisation'
]);

bash
CLIENT_ID = "YOUR-CLIENT-ID"
CLIENT_SECRET = "YOUR-CLIENT-SECRET"
REDIRECT_URI = "http://localhost:8888/xero-php-oauth2-app/callback.php"