框API创建共享链接
本文关键字:链接 共享 创建 API | 更新日期: 2023-09-27 18:30:05
我正在尝试将一些文档上传到Box,并为每个文档创建和检索共享链接。这是我正在使用的代码,但我总是检索403:access_denied_infection_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;
您需要提供访问令牌和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方法。如果有帮助,请将其标记为"答案"。
看起来好像您正在使用第三方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;