Вопрос

Unable to access root folder from my box account, I am getting error as :

{System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at Program.Main(String[] args) in ----.cs :line 110}

Am I missing anything ?

response = null;
data = new StringBuilder();
byteArray = Encoding.UTF8.GetBytes(data.ToString());

// Setup the Request
url_folder_0 = "https://api.box.com/2.0/folders/0/"
request = (HttpWebRequest)WebRequest.Create(url_folder_0);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Headers.Add("Authorization: Bearer " + accessToken);

// Write data
postStream = request.GetRequestStream();
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();

// Send Request & Get Response
response = (HttpWebResponse)request.GetResponse();
Это было полезно?

Решение

To get the info about /folders/0 you need to do a GET request.

Change your line

request.Method = "POST";

to

request.Method = "GET";

here's the CRUD decoder ring for Box's APIs

POST   = Create
GET    = Read
PUT    = Update
DELETE = Delete
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top