SquareUp请求令牌:禁止

时间:2018-10-19 16:33:41

标签: c# square

我正在.NET 4.6.2中工作,并且在尝试引用标准2.0的Square.Connect库时遇到绑定问题,因此我尝试手动编写代码。

public ActionResult RequestToken(string code)
{
if (!string.IsNullOrEmpty(code))
{
    string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

    SquareUpRequest squareUpRequest = new SquareUpRequest()
    {
        client_id = "Application ID (Not sandbox)",
        client_secret = "Personal Access Token",
        code = code
    };

    var client = new RestSharp.RestClient(baseUrl);
    var request = new RestSharp.RestRequest("https://connect.squareup.com/oauth/token", RestSharp.Method.POST);
    request.RequestFormat = RestSharp.DataFormat.Json;
    request.AddBody(squareUpRequest);
    request.AddHeader("Authorization", "Client OAuthApplicationSecret");

    var response = client.Execute(request);
}


return View();

}

我假设我可以多次请求令牌。 SquareUpRequest是一个自定义类。

您看到有什么不对吗?

1 个答案:

答案 0 :(得分:0)

哇。几小时的地狱之后,我才注意到:

 var request = new RestSharp.RestRequest("https://connect.squareup.com/oauth/token", RestSharp.Method.POST);

应该是

 var request = new RestSharp.RestRequest("https://connect.squareup.com/oauth2/token", RestSharp.Method.POST);