Box.com共享文件夹上的链接

时间:2014-03-28 18:57:10

标签: php permissions box-api shared-directory

我正在为box.com使用这个php类 https://github.com/golchha21/BoxPHPAPI

我已经创建了自己的功能来共享像这样的文件夹

public function share_folder($folder_id) {
    $url = $this->build_url("/folders/".$folder_id);
    $params = array('shared_link' => array('access' => 'open', 'permissions' =>
        array('can_download' => 'true', 'can_preview' => 'true')));
    return json_decode($this->post($url, json_encode($params)), true);
}

我和这篇文章有同样的问题。 Access denied error message when trying to create a shared link to a folder in Box

有没有人对此有所修正或知道为什么会这样?

更新

我明白了:

    public function share_folder($folder_id) {
                $url = $this->build_url("/folders/".$folder_id);
                $params = array('shared_link' => array('access' => 'open', 'permissions' =>
array('can_download' => true, 'can_preview' => true)));
                return json_decode($this->put($url, $params), true);

我必须改变它以放置和取消json_encode

希望这有助于其他人

1 个答案:

答案 0 :(得分:0)

现在使用共享功能更新API。

<?php
    include('library/BoxAPI.class.php');

    $client_id      = 'CLIENT ID';
    $client_secret  = 'CLIENT SECRET';
    $redirect_uri   = 'REDIRECT URL';

    $box = new Box_API($client_id, $client_secret, $redirect_uri);

    if(!$box->load_token()){
        if(isset($_GET['code'])){
            $token = $box->get_token($_GET['code'], true);
            if($box->write_token($token, 'file')){
                $box->load_token();
            }
        } else {
            $box->get_code();
        }
    }

    // Share folder
    $params['shared_link']['access'] = 'ACCESS TYPE'; //open|company|collaborators
    print_r($box->share_folder('FOLDER ID', $params));

    // Share file
    $params['shared_link']['access'] = 'ACCESS TYPE'; //open|company|collaborators
    print_r($box->share_file('File ID', $params);
?>

看看here 下载:BoxPHPAPI