Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
@hlu2 hlu2 Hello World 2a7bafe Apr 13, 2018
1 contributor

Users who have contributed to this file

48 lines (38 sloc) 1.17 KB
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use QuickBooksOnline\API\DataService\DataService;
session_start();
function processCode()
{
// Create SDK instance
$config = include('config.php');
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth2',
'ClientID' => $config['client_id'],
'ClientSecret' => $config['client_secret'],
'RedirectURI' => $config['oauth_redirect_uri'],
'scope' => $config['oauth_scope'],
'baseUrl' => "development"
));
$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
$parseUrl = parseAuthRedirectUrl($_SERVER['QUERY_STRING']);
/*
* Update the OAuth2Token
*/
$accessToken = $OAuth2LoginHelper->exchangeAuthorizationCodeForToken($parseUrl['code'], $parseUrl['realmId']);
$dataService->updateOAuth2Token($accessToken);
/*
* Setting the accessToken for session variable
*/
$_SESSION['sessionAccessToken'] = $accessToken;
}
function parseAuthRedirectUrl($url)
{
parse_str($url,$qsArray);
return array(
'code' => $qsArray['code'],
'realmId' => $qsArray['realmId']
);
}
$result = processCode();
?>
You can’t perform that action at this time.