问题描述
UPDATE:我想出来并发布了下面的答案。
UPDATE: I figured it out and posted the answer below.
我想做的是更新任何文件属性。描述,名称,任何东西,但无论我如何格式化我得到一个403。
All I'm trying to do is update any file attribute. Description, name, anything, but no matter how I format it I get a 403.
我需要能够修改一个文件, API从云应用程序。我更新了别人的代码从V1,但他们不再可用...我尝试了很多东西,但大多只是得到403禁止错误。
I need to be able to modify a file so it can be shared via the Box API from a cloud app. I'm updating someone else's code from V1, but they are no longer available... I've tried many things but mostly just get 403 Forbidden errors.
没有OAuth2的问题,工作正常,我可以列出文件和文件夹,但不能修改它们。这个问题是关于共享,但我也不能更改描述。箱子帐户是我的,我使用我的管理员凭据验证。任何建议将不胜感激。
There are no issues with OAuth2, that works fine and I can list files and folders, but can not modify them. This question is about sharing, but I can't change a description either. The box account is mine and I authenticate with my admin credentials. Any suggestions would be appreciated.
这里是我使用的方法。我传入fileId和令牌,为了简洁,我省略了try / catch等。
Here is the method I am using. I pass in the fileId and token and I've left out try/catch etc. for brevity.
string uri = string.Format("https://api.box.com/2.0/files/{0}", fileId);
string body = "{\"shared_link\": {\"access\": \"open\"}}";
byte[] postArray = Encoding.ASCII.GetBytes(body);
using (var client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("Authorization: Bearer " + token);
var response = client.UploadData(uri, postArray);
var responseString = Encoding.Default.GetString(response);
}
感谢。
推荐答案
好的,我的荷马辛普森时刻...
Okay, My Homer Simpson moment...
UploadData是一个POST,我需要做一个PUT。这是解决方案。
UploadData is a POST, I needed to do a PUT. Here is the solution.
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;
这篇关于无法使用Box API V2创建共享链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!