为此,我必须将文件上传到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;
}
}发布于 2013-07-15 17:18:26
来自文档:https://developers.box.com/oauth/ (请参阅“获取访问令牌”)
当将auth代码交换为一组访问令牌和刷新令牌时,您需要向https://www.box.com/api/oauth2/token端点发出POST请求。
尝试将您正在添加的内容添加到标题的“授权”部分,并将其放入URL编码的POST正文中。
或者更好的是,尝试可用的.NET SDK,它将为您处理OAuth工作流的这一部分:https://github.com/box/box-windows-sdk-v2。
发布于 2013-08-21 21:46:58
您还需要将编码设置为:
request.RequestFormat = DataFormat.Xml;https://stackoverflow.com/questions/17491941
复制相似问题