我正在尝试使用RESTSharp
在Box上创建一个简单的文件夹,但我很难过。我一直收到这个错误:
{ “类型”: “错误”, “状态”:400, “代码”: “BAD_REQUEST”, “HELP_URL”: “http://developers.box.com/docs/#errors”, “消息” :“可以 不解析JSON“,”request_id“:”1474540366505ba7a11bdcd“}
这是我的代码:
static string box(string resourceURL, string APIKey, string authToken)
{
RestClient client = new RestClient();
client.BaseUrl = "https://api.box.com/2.0";
var request = new RestRequest(Method.POST);
request.Resource = resourceURL;
string Headers = string.Format("Authorization: BoxAuth api_key={0}&auth_token={1}", APIKey, authToken);
request.AddHeader("Authorization", Headers);
request.AddParameter("name", "TestFolder");
// request.RequestFormat = DataFormat.Json;
var response = client.Execute(request);
return response.Content;
}
我错过了什么?在此先感谢您的帮助。
答案 0 :(得分:1)
您可能还想看看最近创建的github repo,其中一些人正在C#Box SDK上进行协作。 https://github.com/jhoerr/box-csharp-sdk-v2
答案 1 :(得分:0)
感谢您的帮助,这是最终有效的准确代码。
static string box(string APIKey, string authToken)
{
RestClient client = new RestClient();
client.BaseUrl = "https://api.box.com/2.0";
var request = new RestRequest(Method.POST);
request.Resource = "/folders/0";
string Headers = string.Format("BoxAuth api_key={0}&auth_token={1}", APIKey, authToken);
request.AddHeader("Authorization", Headers);
request.AddParameter("text/json", "{\"name\" : \"TestFolderName\"}", ParameterType.RequestBody);
//request.RequestFormat = DataFormat.Json;
var response = client.Execute(request);
return response.Content;
}
答案 2 :(得分:0)
static string folderCreation(string APIKey,string authToken) {
RestClient client = new RestClient();
client.BaseUrl = "https://api.box.com/2.0/folders";
var request = new RestRequest(Method.POST);
string Headers = string.Format("Bearer {0}", authToken);
request.AddHeader("Authorization", Headers);
request.AddParameter("application/json", "{\"name\":\"Youka\",\"parent\":{\"id\":\"0\"}}", ParameterType.RequestBody);
var response = client.Execute(request);
return response.Content;
}