【发布时间】:2017-04-11 02:38:08
【问题描述】:
我有我的身份验证码、客户 ID、客户密码,现在要将文件上传到我的 Box 帐户,我需要有 ACCESS TOKEN。我正在使用在 stackoverflow 中复制的以下代码来获取 ACCESS TOKEN。
public string 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;
return strResponse;
}
catch (Exception ex)
{
throw ex;
}
}
响应的内容类型是 HTML,而不是他们在文档页面中提到的 JSON。请您帮助我如何使用 asp.net 应用程序从 BOX API 获取访问令牌?
【问题讨论】:
-
你会得到什么 html 响应。看一下,因为它可能是一条错误消息。收到成功的响应码了吗?
-
是的。收到成功的响应码。
标签: c# asp.net access-token restsharp box