我必须将文件上传到box.com,因为我需要授权并获取accesstoken
和刷新令牌。我在 c# asp.net 中找不到任何代码。我想要使用 c# 和 asp.net 进行身份验证的代码以及用于获取accesstoken
和刷新令牌的代码。我尝试了下面的代码,因为页面再次过期请求而出现错误。这是 c# asp.net 中的代码。我正在尝试使用Restsharp
public void GetAccessToken(string code, string ClientId, string ClientSecret)
{
RestClient rs = new RestClient();
string grant_type = "authorization_code";
RestRequest request = new RestRequest(Method.POST);
IRestRequest reuest = request;
string strHeaders = null;
RestResponse response = default(RestResponse);
IRestResponse resp = response;
string strResponse = null;
try
{
rs.BaseUrl = "https://www.box.com/api/oauth2/token";
request.Resource = "oauth2/token";
strHeaders = string.Format("grant_type={0}&code={1}&client_id={2}&client_secret={3}", grant_type, code, clientId, Clientsecret);
request.AddHeader("Authorization", strHeaders);
resp = rs.Execute(reuest);
strResponse = resp.Content;
Label1.Text = strResponse;
}
catch (Exception ex)
{
throw ex;
}
}