简体   繁体   English

WooCommerce Rest API返回404未找到

[英]WooCommerce Rest API returns 404 not found

I am trying to pull a count of products from WooCommerece using the REST API: 我试图使用REST API从WooCommerece中提取产品数量:

http://www.skyverge.com/woocommerce-rest-api-docs.html#authentication/over-https http://www.skyverge.com/woocommerce-rest-api-docs.html#authentication/over-https

I can visit this page and I receive valid JSON: 我可以访问此页面并收到有效的JSON:

https://[OMITTED].com/wc-api/v1 HTTPS:// [省略]的.com / WC-API / V1

When I visit /wc-api/v1/products/count, I get a 404 error: 当我访问/ wc-api / v1 / products / count时,我收到404错误:

{"errors":[{"code":"woocommerce_api_authentication_error","message":"Consumer Key is missing"}]} {“errors”:[{“code”:“woocommerce_api_authentication_error”,“message”:“消费者密钥丢失”}}}

Under WooCommerce > Settings > Checkout, secure checkout has been enabled. 在WooCommerce>设置>结帐下,已启用安全结帐。 Is my code incorrect? 我的代码不正确吗? It works fine with a new 2.1 install. 它在新的2.1安装下运行良好。

Here is my code: 这是我的代码:

    public bool Authenticate()
    {
        try
        {
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(m_BaseUrl + "/products/count");
            //myHttpWebRequest.Accept = "text/xml";
            string userP = m_UserName + ":" + m_Password;
            byte[] authBytes = Encoding.UTF8.GetBytes(userP).ToArray();
            myHttpWebRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes));
            WebResponse httpResponse = myHttpWebRequest.GetResponse();
            Stream responseStream = httpResponse.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            string resultData = reader.ReadToEnd();
            responseStream.Close();
            httpResponse.Close();
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }


GET https://www.[OMITTED].com/wc-api/v1/products/count HTTP/1.1
Authorization: Basic [OMITTED]
Host [OMITTED]
Connection: Keep-Alive

You need to include the oauth_consumer_key in your request url. 您需要在请求网址中包含oauth_consumer_key。

Login into your WP-Admin and go to your user profile to generate your API keys. 登录您的WP-Admin并转到您的用户个人资料以生成您的API密钥。 You should see something with consumer key and consumer secret, in section Woocommerce API Keys. 您应该在Woocommerce API Keys部分中看到具有消费者密钥和消费者秘密的内容。

After you get the value for the consumer key your sample request will be: 获得使用者密钥的值后,您的样本请求将是:

http or https://yourdomain.com/wc-api/v2/products/?oauth_consumer_key=ck_670ae128f1ebb1859ba03b2171f8ca7c http或https://yourdomain.com/wc-api/v2/products/?oauth_consumer_key=ck_670ae128f1ebb1859ba03b2171f8ca7c

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM