0

我正在尝试将一些文档上传到 Box 并为每个文档创建和检索共享链接。这是我使用的代码,但我总是检索 403:access_denied_insufficient_permissions。知道为什么会这样吗?

希望你能帮我!谢谢。

// CREATE THE FILE
BoxFileRequest req = new BoxFileRequest
{
    Name = zipFile.Name,
    Parent = new BoxRequestEntity { Id = newFolder.Id}
};
BoxFile uploadedFile = client.FilesManager.UploadAsync(req, stream).Result;

//REQUEST SHARED LINK
BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest()
{
       Access = BoxSharedLinkAccessType.open,
       Permissions = new BoxPermissionsRequest
       {
             Download = BoxPermissionType.Open,
             Preview = BoxPermissionType.Open,
       }
};

BoxFile fileLink = fileManager.CreateSharedLinkAsync(uploadedFile.Id, sharedLinkReq).Result;
4

2 回答 2

1

看起来好像您正在使用第 3 方 BoxSync V2 API 对象。如果您只想直接对 API 进行编码,我遇到了类似的问题。如果您查看帖子,您将看到答案。这是我使用的代码,它可以工作。

    string uri = String.Format(UriFiles, fileId);
    string response = string.Empty;
    string body = "{\"shared_link\": {\"access\": \"open\"}}";
    byte[] postArray = Encoding.ASCII.GetBytes(body);

    try
    {
        using (var client = new WebClient())
        {
            client.Headers.Add("Authorization: Bearer " + token);
            client.Headers.Add("Content-Type", "application/json");
            response = client.UploadString(uri, "PUT", body);
        }
    }
    catch (Exception ex)
    {
        return null;
    }
    return response;
于 2014-04-16T14:40:41.683 回答
1

您需要提供访问令牌和 url。我使用了以下代码,您将获得 JSON 格式的响应。有关更多参考,请检查框 API 文档

        HttpWebRequest httpWReq = HttpWebRequest)WebRequest.Create("https://api.box.com/2.0/folders/" + FolderID);
        ASCIIEncoding encoding = new ASCIIEncoding();
        string putData = "{\"shared_link\": {\"access\": \"open\"}}";
        byte[] data = encoding.GetBytes(putData);
        httpWReq.Method = "PUT";
        httpWReq.Headers.Add("Authorization", "Bearer ");
        httpWReq.ContentType = "application/json";
        httpWReq.ContentLength = data.Length;

在此之后使用 httpwebrequest PUT 方法。如果有帮助,请将其标记为答案。

于 2014-04-04T11:30:19.143 回答