1

我正在尝试使用 V2 API 通过 cURL 将文件上传到 Box。文件上传成功,但返回对象的 shared_link 属性为空。文档中似乎没有任何内容可以解释这种情况。这种情况的一个特殊问题是我们仍在使用旧的 OAuth 流程进行用户登录。这是 V2 API 提供的功能的一个因素吗?我们已经计划切换到 OAuth2 流程,但如果有必要在上传时恢复 shared_link,我将加快我们的升级计划。

以下是相关代码:

209     private static $api_upload_url = 'https://upload.box.com/api/2.0/';
210     public function upload($token, $file, $folder) {
211             
212         $api_key = $config['boxnet_api_key'];
213         $params = array(
214             'filename' => '@' . $file,
215             'parent_id' => $folder,
216         );          
217                 
218         $ch = curl_init();
219         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
220         curl_setopt($ch, CURLOPT_URL, self::$api_upload_url . 'files/content');
221         curl_setopt($ch, CURLOPT_POST, 2);
222         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
223         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: BoxAuth api_key=$api_key&auth_token=$token"));
224                 
225         $response = json_decode(curl_exec($ch));
226         curl_close($ch);
227                 
228         return $response;
229     }

这是响应的净化版本:

stdClass Object
    (
        [type] => file
        [id] => /* Removed */
        [sequence_id] => 0
        [etag] => 0
        [sha1] => /* Removed */
        [name] => /* Removed */
        [description] => 
        [size] => 10618
        [path_collection] => stdClass Object
            (
                 [total_count] => 1
                 [entries] => Array
                     (
                         [0] => stdClass Object
                             (
                                 [type] => folder
                                 [id] => 0
                                 [sequence_id] => 
                                 [etag] => 
                                 [name] => All Files
                             )

                     )

            )
        [created_at] => /* Removed */
        [modified_at] => /* Removed */
        [trashed_at] => 
        [purged_at] => 
        [content_created_at] => /* Removed */
        [content_modified_at] => /* Removed */
        [created_by] => stdClass Object
            (
                [type] => user
                [id] => /* Removed */
                [name] => /* Removed */
                [login] => /* Removed */
            )
        [modified_by] => stdClass Object
            (
                [type] => user
                [id] => /* Same as modified_by */
                [name] => /* Same as modified_by */
                [login] => /* Same as modified_by */
            )
        [owned_by] => stdClass Object
            (
                [type] => user
                [id] => /* Same as modified_by */
                [name] => /* Same as modified_by */
                [login] => /* Same as modified_by */
            )
        [shared_link] => 
        [parent] => stdClass Object
            (
                [type] => folder
                [id] => 0
                [sequence_id] => 
                [etag] => 
                [name] => All Files
            )
        [item_status] => active
    )

有什么想法吗?还是只是身份验证令牌没有足够的权限(由于是通过旧方法创建的)来获取该数据?

4

1 回答 1

1

必须为文件和文件夹显式创建共享链接。这是相关文档

我们仍在使用旧的 OAuth 流程进行用户登录。

您暂时可以将 v1 身份验证令牌与 v2 API 一起使用,但据我所知,这将在年底左右停止工作。

于 2013-04-12T16:06:35.133 回答