Box.com 获取请求 RestSharp C#
Box.com Get Request RestSharp C#
我有一个问题,我的 POST 请求 returns 返回一个令牌,但是当我更改我的代码以使用该令牌并尝试 GET 请求时,它给我一个“状态:0”信息。我写这段代码错了吗?我已经尝试将“Bearer”+ token 添加到身份验证中。
ErrorException = {“无法发送具有此动词类型的内容正文。”}
Post:
var client = new RestClient("https://api.box.com/oauth2/token");
RestRequest 请求 = new RestRequest() { Method = Method.Post };
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", $"{client_ID}");
request.AddParameter("client_secret", $"{client_secret}");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("box_subject_type", "enterprise");
request.AddParameter("box_subject_id", enterpriseID);
var response = await client.ExecuteAsync(request);
var responseMessage = JObject.Parse(response.Content);
获取:
var client2 = new RestClient("https://api.box.com/2.0/files/154072314030");
var request2 = new RestRequest() { Method = Method.Get };
request2.AddHeader("Authorization", token);
request2.AddHeader("Content-Type", "application/json");
var response2 = await client2.ExecuteAsync(request2);
var responseMessage2 = JObject.Parse(response2.Content);
最终使用了他们的 SDK。这就是我能够登录并提取文件夹中项目的方式:
BoxFolder folderWithLink = new BoxFolder();
BoxSharedLinkRequest linkRequest = new BoxSharedLinkRequest();
int offset = 0;
int count = 0;
string folderID = "";
//create connection to Box.com
var boxConfig = new BoxConfigBuilder("CLIENT ID", "CLIENT SECRET", "Enterprise ID", "PRIVATE KEY", "PRIVATE KEY PASSWORD", "PUBLIC KEY ID").Build();
var boxJWT = new BoxJWTAuth(boxConfig);
var adminToken = await boxJWT.AdminTokenAsync();
var client = boxJWT.AdminClient(adminToken);
//Get the parent folder information and find the Batch folderID
while (folderID == "")
{
var batches = await client.FoldersManager.GetFolderItemsAsync("FOLDER ID", 250, offset);
foreach (var batchEntry in batches.Entries)
{
Console.Writeline(Batch.Name);
}
我有一个问题,我的 POST 请求 returns 返回一个令牌,但是当我更改我的代码以使用该令牌并尝试 GET 请求时,它给我一个“状态:0”信息。我写这段代码错了吗?我已经尝试将“Bearer”+ token 添加到身份验证中。
ErrorException = {“无法发送具有此动词类型的内容正文。”}
Post:
var client = new RestClient("https://api.box.com/oauth2/token"); RestRequest 请求 = new RestRequest() { Method = Method.Post };
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", $"{client_ID}");
request.AddParameter("client_secret", $"{client_secret}");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("box_subject_type", "enterprise");
request.AddParameter("box_subject_id", enterpriseID);
var response = await client.ExecuteAsync(request);
var responseMessage = JObject.Parse(response.Content);
获取:
var client2 = new RestClient("https://api.box.com/2.0/files/154072314030");
var request2 = new RestRequest() { Method = Method.Get };
request2.AddHeader("Authorization", token);
request2.AddHeader("Content-Type", "application/json");
var response2 = await client2.ExecuteAsync(request2);
var responseMessage2 = JObject.Parse(response2.Content);
最终使用了他们的 SDK。这就是我能够登录并提取文件夹中项目的方式:
BoxFolder folderWithLink = new BoxFolder(); BoxSharedLinkRequest linkRequest = new BoxSharedLinkRequest();
int offset = 0;
int count = 0;
string folderID = "";
//create connection to Box.com
var boxConfig = new BoxConfigBuilder("CLIENT ID", "CLIENT SECRET", "Enterprise ID", "PRIVATE KEY", "PRIVATE KEY PASSWORD", "PUBLIC KEY ID").Build();
var boxJWT = new BoxJWTAuth(boxConfig);
var adminToken = await boxJWT.AdminTokenAsync();
var client = boxJWT.AdminClient(adminToken);
//Get the parent folder information and find the Batch folderID
while (folderID == "")
{
var batches = await client.FoldersManager.GetFolderItemsAsync("FOLDER ID", 250, offset);
foreach (var batchEntry in batches.Entries)
{
Console.Writeline(Batch.Name);
}