radzserg/

box-content

该包最新版本(dev-master)没有可用的许可证信息。

Box.com 内容 API SDK V2。

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

This package is not auto-updated.

Last update: 2024-09-20 19:08:49 UTC


README

警告:这不是一个完整且经过充分测试的 SDK。这只是一个使用示例。我没有太多时间实现所有 API 端点。我只实现了我需要的部分。但这很容易扩展。我使用了 box.com 平台集成。

从这里开始 box.com 文档

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;

如果你需要更多端点 - 欢迎提交拉取请求 :)