PHP code example of r4kib / cloudbeds-api

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

    

r4kib / cloudbeds-api example snippets


$cloudbeds = new \R4kib\Cloudbeds\Cloudbeds([
    'clientId'                => 'yourId',          // The client ID assigned to you by Amazon
    'clientSecret'            => 'yourSecret',      // The client password assigned to you by Amazon
    'redirectUri'             => 'yourRedirectUri',  // The return URL you specified for your app on Amazon
    'version'                 => 'v1.1'  // API Version, default v1.1
]);

$cloudbeds = resolve("R4kib\\Cloudbeds\\Cloudbeds");

$oauthHelper= $cloudbeds->getOauthHelper();
// Get authorization code
if (!isset($_GET['code'])) {
    
    // Get authorization URL
    $authorizationUrl = $oauthHelper->getAuthorizationUrl();

    // Redirect user to authorization URL
    header('Location: ' . $authorizationUrl);
    exit;
} else {
    // Get access token
        $accessToken = $oauthHelper->getAccessToken(
            'authorization_code',
            [
                'code' => $_GET['code']
            ]
        );

    // Get resource owner
        $resourceOwner = $oauthHelper->getResourceOwner($accessToken);
        
    // Now you can store the results to session etc.
    $_SESSION['accessToken'] = $accessToken;
    $_SESSION['resourceOwner'] = $resourceOwner;

    var_dump(
        $resourceOwner->getID(),
        $resourceOwner->getFirstName(),
        $resourceOwner->getLastName(),
        $resourceOwner->getEmail()
    );
}

// $params is [key=>value] array. See cloudbeds.com API documentation to view params.
 $cloudbeds->get('/path',$accessToken,$params);
 $cloudbeds->post('/path',$accessToken,$params);
 $cloudbeds->put('/path',$accessToken,$params);
 $cloudbeds->delete('/path',$accessToken,$params);

php artisan vendor:publish --config