【问题标题】:Zoho Invoice API Error {"error":"invalid_client"} while requesting for tokenZoho Invoice API 在请求令牌时出错 {"error":"invalid_client"}
【发布时间】:2022-01-05 07:06:29
【问题描述】:

在访问 Zoho api 以获取令牌时,我收到以下错误:

{"error":"invalid_client"}

第1步:我正在申请验证码,验证码返回成功。

这是我正在使用的 API。 https://accounts.zoho.com/oauth/v2/auth?scope=xxx&client_id=yyyyy&state=zzzz&response_type=code&redirect_uri=pppppp&access_type=offline

第 2 步:令牌请求 使用在步骤 1 中获得的身份验证代码,我当时正在对令牌进行发布请求,但我得到了以下异常。

var authTokenRequestData = new
{
    code= code,
    client_id= _clientId,
    client_secret =_clientSecret,
    redirect_uri = _redirectUri,
    grant_type = "authorization_code"
};


var data = new StringContent(JsonConvert.SerializeObject(authTokenRequestData), Encoding.UTF8, "application/json");
    
var url = "https://accounts.zoho.com/oauth/v2/token";

string result = "";

using (var client = new HttpClient())
    {
        var response = await client.PostAsync(url, data);
        result = await response.Content.ReadAsStringAsync();
    }

它给了我例外

{error:invalid_client}

我已经验证了我的 client_id 和 client_secret。只有正确。

这是我注册的基于服务器的应用程序客户端。

对此的任何帮助都非常感谢。

【问题讨论】:

    标签: zoho


    【解决方案1】:

    我可以通过更改请求 Content-Type 来解决这个问题

    "Content-Type", "application/x-www-form-urlencoded"
    

    完整代码如下:

    string _domain = ".in"; /*Ensure you're using the correct .com or .in domain*/
    var url = "https://accounts.zoho"+ _domain + "/oauth/v2/token";
    
    string result = "";
    
    using (var client = new HttpClient())
        {
            var data = new Dictionary<string, string>
            {
                { "Content-Type", "application/x-www-form-urlencoded" },
                { "code", code },
                { "client_id", _clientId },
                { "client_secret", _clientSecret },
                { "redirect_uri", _redirectUri },
                { "grant_type", "authorization_code" },
                { "access_type", "offline" }
             };
    
    var response = await client.PostAsync(url, new FormUrlEncodedContent(data));
    result = await response.Content.ReadAsStringAsync();
        }
    

    【讨论】:

      【解决方案2】:

      这个问题可能还有一个原因。

      {"error":"invalid_client"}
      

      检查您是否使用了正确的域。 (.in .com 或...)

      例如,您使用 .in 而不是 .com,反之亦然

      在我使用 .in 域但我的域是 .com 时,我遇到了同样的错误 {"error":"invalid_client"}

      我正在使用这个:

      var url = "https://accounts.zoho.in/oauth/v2/token"; 
      

      我将其替换如下,这解决了我的问题。

      var url = "https://accounts.zoho.com/oauth/v2/token";  
      

      【讨论】:

        猜你喜欢
        • 2014-10-25
        • 2018-02-18
        • 2022-07-14
        • 2022-07-07
        • 2013-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-20
        相关资源
        最近更新 更多