2014-04-12 38 views
0

更新共享鏈接:我想通了,並張貼下面的答案。無法創建使用盒API V2

我想要做的就是更新任何文件屬性。說明,名稱,任何事情,但無論我如何格式化我得到一個403

我需要能夠修改一個文件,以便它可以通過從雲應用程序的API盒共享。我從V1更新別人的代碼,但他們不再可用...我已經嘗試了很多東西,但主要是得到403 Forbidden錯誤。

有與無的OAuth2問題,即工作正常,我可以列出文件和文件夾,但不能修改它們。這個問題是關於共享的,但我也不能改變描述。箱子帳戶是我的,我使用我的管理員憑據進行身份驗證。任何建議,將不勝感激。

以下是我正在使用的方法。我傳入了fileId和token,爲了簡潔起見我省略了try/catch等。

 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); 
     } 

謝謝。

回答

1

好吧,我辛普森一刻......

UploadData是POST,我需要做一個放。這是解決方案。

 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; 
0

嘗試將您的內容類型更改爲'multipart/form-data'?

我剛剛擡頭的api位於:https://developers.box.com/docs/#files-upload-a-file

,它看起來像服務器期待一個多後

這裏堆棧溢出職位上發佈多數據:

ASP.NET WebApi: how to perform a multipart post with file upload using WebApi HttpClient

+0

感謝您的答覆。是的,我閱讀了文檔。所有我想要做的是這樣的:捲曲https://api.box.com/2.0/files/FILE_ID \ -H「授權:承載ACCESS_TOKEN」 \ -d「{‘名’:「新名稱。 jpg「}'\ -X PUT,如果我放置multipart/form-data或application/json,我仍然會得到403。 – CodeChops