radzserg/box-content

There is no license information available for the latest version (dev-master) of this package.

Box.com Content API SDK V2.

dev-master 2016-07-07 15:41 UTC

This package is not auto-updated.

Last update: 2024-10-04 19:17:08 UTC


README

Warning: this is not full and well tested SDK. This is just an example of usages. I don't have much time to implement all API endpoints. I implemented only what I needed. But this could be easily extended. I used box.com platform integration.

Start from here box.com docs

use radzserg\BoxContent\BoxContentException;
use radzserg\BoxContent\Client;

$client = new Client([
    'publicKeyId' => 'public_key',  // Public Key ID generated by Box and provided upon submission of a Public Key. Identifies which Public Key a client is using.
    'enterpriseId' => 'enterprise_id', // enterprise_id for a token specific to an enterprise
    'boxUserId' => 'user_id',  // app user_id for a token specific to an individual app user. https://docs.box.com/docs/app-users#section-2-create-an-app-user
    'privateCertPath' => '/path/to/cert.pem',    // path to your private cert
    'certPassword' => 'password',
    'clientId' => 'client_id',      // app client id
    'secretId' => 'secret_id',      // app secret id
    // next fields are optional

    // specify cache files in order not to sign every requets but save them to cache files
    // tokens will be automatically refreshed when they expire
    'appTokenCachePath' => '/path/to/boxcom_app_token.json',    // path to file where app token will be saved
    'userTokenCachePath' => '/path/to/boxcom_user_token.json',  // path to file where user token will be saved
]);

// first create platform user then we will use this user for other operations
try {
    $platformUser = $client->user->createPlatformUser(['name' => 'John Doe']);
} catch (BoxContentException $e) {
    echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n\n";
}

// update your content boxUserId with received user id
try {
    $params = [
        'attributes' => json_encode([
            'parent' => ['id' => "0"],  // upload to root user folder
            'name' => 'composer3.json',
        ])
    ];
    $file = $client->document->uploadFile(fopen('../myfile.jpg', 'r'), $params);

    var_dump($file);
} catch (BoxContentException $e) {
    echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n\n";
}

$content = $client->document->get('73301640961')->thumbnail('png', ['min_height' => 32, 'min_width' => 32]);
echo '<img src="data:image/png;base64,' . base64_encode($content) . '"/>';


$document = $client->document->get('73301640961', ['expiring_embed_link']);
$link = $document->getData('expiring_embed_link');
echo isset($link['url']) ? $link['url'] : null;

If you need more endpoints - pull requests are welcome :)