square connect api获取令牌错误

时间:2015-01-22 13:13:26

标签: asp.net square-connect

我已成功从OAuth授权中获取广场代码。但我无法交换它以获取访问令牌。我收到了这个回复:

{"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参数,尽管我发送了这个参数。

1 个答案:

答案 0 :(得分:0)

this解决方案解决了这个问题: