【问题标题】:square connect api obtain token errorsquare connect api获取token错误
【发布时间】:2015-01-27 21:37:30
【问题描述】:

我已经从 Square 中成功获取了 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 参数,虽然我发送了这个参数。

【问题讨论】:

    标签: asp.net square-connect


    【解决方案1】:

    this解决方案解决了问题:

    【讨论】:

    • 我在 php.ini 中遇到了同样的问题。不确定其中的哪一部分是解决方案,即 url 编码?我在php中试过这个,但问题仍然存在 curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode(json_encode($array)));
    猜你喜欢
    • 2016-10-10
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多