我必須上傳文件到box.com因爲我需要授權並獲取accesstoken
和刷新令牌。我沒有在c#asp.net中找到任何代碼。我希望使用c#和asp.net進行身份驗證的代碼以及獲取accesstoken
和刷新令牌的代碼。我在下面的代碼嘗試獲取錯誤,因爲頁面已過期請求再次。 這裏是C#asp.net.I代碼使用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;
}
}
非常感謝期待你的答覆 – user2514945