square connect api 获取令牌错误

square connect api obtain token error

我已经成功从 OAuth 授权中获取来自 Square 的代码。但我无法交换它来获取访问令牌。我收到这样的回复:

{"message":"Missing required parameter `client_id`","type":"bad_request"}

我的 asp.net 实现如下:

    object item = new { client_id = [app_id], client_secret = [app_secret], code = [authCode] };
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    var json = serializer.Serialize(item);
    HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

    var httpClient = new HttpClient();
    httpClient.BaseAddress = new Uri("https://connect.squareup.com");
    AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Authorization", "Client [app_secret]");
    httpClient.DefaultRequestHeaders.Authorization = auth;
    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    Task<HttpResponseMessage> httpResponse = httpCLient.PostAsync("/oauth2/token", content);
    if (httpResponse.Result.StatusCode != HttpStatusCode.OK)
    {
    }
    string resultContent = httpResponse.Result.Content.ReadAsStringAsync().Result;

此时我卡住了。不明白为什么它说缺少 client_id 参数,尽管我发送了这个参数。

this解决方案解决了问题: