Inheritance: extends XeroPHP\Application
Example #1
0
<?php

use XeroPHP\Application\PublicApplication;
use XeroPHP\Remote\Request;
use XeroPHP\Remote\URL;
// Start a session for the oauth session storage
session_start();
//These are the minimum settings - for more options, refer to examples/config.php
$config = array('oauth' => array('callback' => 'http://localhost/', 'consumer_key' => 'k', 'consumer_secret' => 's'), 'curl' => array(CURLOPT_CAINFO => __DIR__ . '/certs/ca-bundle.crt'));
$xero = new PublicApplication($config);
//if no session or if it is expired
if (null === ($oauth_session = getOAuthSession())) {
    $url = new URL($xero, URL::OAUTH_REQUEST_TOKEN);
    $request = new Request($xero, $url);
    //Here's where you'll see if your keys are valid.  You can catch a BadRequestException.
    try {
        $request->send();
    } catch (Exception $e) {
        print_r($e);
        if ($request->getResponse()) {
            print_r($request->getResponse()->getOAuthResponse());
        }
    }
    $oauth_response = $request->getResponse()->getOAuthResponse();
    setOAuthSession($oauth_response['oauth_token'], $oauth_response['oauth_token_secret']);
    printf('<a href="%s">Click here to Authorize</a>', $xero->getAuthorizeURL($oauth_response['oauth_token']));
    exit;
} else {
    $xero->getOAuthClient()->setToken($oauth_session['token'])->setTokenSecret($oauth_session['token_secret']);
    if (isset($_REQUEST['oauth_verifier'])) {
        $xero->getOAuthClient()->setVerifier($_REQUEST['oauth_verifier']);
Example #2
0
<?php

use XeroPHP\Application\PublicApplication;
use XeroPHP\Remote\Request;
use XeroPHP\Remote\URL;
//These are the minimum settings - for more options, refer to examples/config.php
$config = array('oauth' => array('callback' => 'http://localhost/', 'consumer_key' => 'k', 'consumer_secret' => 's', 'curl' => array(CURLOPT_CAINFO => __DIR__ . '/certs/ca-bundle.crt')));
$xero = new PublicApplication($config);
//if no session or if it is expired
if (null === ($oauth_session = getOAuthSession())) {
    $url = new URL($xero, URL::OAUTH_REQUEST_TOKEN);
    $request = new Request($xero, $url);
    //Here's where you'll see if your keys are valid.  You can catch a BadRequestException.
    try {
        $request->send();
    } catch (Exception $e) {
        echo $e->getCode();
        print_r($request->getResponse()->getOAuthResponse());
    }
    $oauth_response = $request->getResponse()->getOAuthResponse();
    setOAuthSession($oauth_response['oauth_token'], $oauth_response['oauth_token_secret']);
    printf('<a href="%s?oauth_token=%s">Click here to Authorize</a>', $xero->getAuthorizeURL(), $oauth_response['oauth_token']);
    exit;
} else {
    $xero->getOAuthClient()->setToken($oauth_session['token'])->setTokenSecret($oauth_session['token_secret']);
    if (isset($_REQUEST['oauth_verifier'])) {
        $xero->getOAuthClient()->setVerifier($_REQUEST['oauth_verifier']);
        $url = new URL($xero, URL::OAUTH_ACCESS_TOKEN);
        $request = new Request($xero, $url);
        $request->send();
        $oauth_response = $request->getResponse()->getOAuthResponse();