1

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

4

1 回答 1

0

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

于 2015-01-27T13:37:30.563 回答