WooCommerce Rest API ส่งคืน 404 ไม่พบ

ฉันกำลังพยายามดึงผลิตภัณฑ์จำนวนหนึ่งจาก WooCommerece โดยใช้ REST API:

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

ฉันสามารถเยี่ยมชมหน้านี้และฉันได้รับ JSON ที่ถูกต้อง:

https://[ละเว้น].com/wc-api/v1

เมื่อฉันไปที่ /wc-api/v1/products/count ฉันได้รับข้อผิดพลาด 404:

{"errors":[{"code///woocommerce_api_authentication_error","message///Consumer Key is missing"}]}

ใต้ WooCommerce > การตั้งค่า > ชำระเงิน เปิดใช้งานการชำระเงินที่ปลอดภัยแล้ว รหัสของฉันไม่ถูกต้องหรือไม่? มันทำงานได้ดีกับการติดตั้ง 2.1 ใหม่

นี่คือรหัสของฉัน:

    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

person user1255637    schedule 15.03.2014    source แหล่งที่มา
comment
สวัสดี คุณพบปัญหาหรือไม่? ฉันก็เหมือนกันกับ WooCommerce เวอร์ชันล่าสุดของฉัน...   -  person user1635430    schedule 23.04.2015


คำตอบ (1)


คุณต้องรวม oauth_consumer_key ไว้ใน URL คำขอของคุณ

เข้าสู่ระบบ WP-Admin ของคุณและไปที่โปรไฟล์ผู้ใช้ของคุณเพื่อสร้างคีย์ API ของคุณ คุณควรเห็นบางสิ่งที่มีรหัสผู้บริโภคและความลับของผู้บริโภคในส่วน คีย์ Woocommerce API

หลังจากที่คุณได้รับค่าสำหรับรหัสผู้บริโภค คำขอตัวอย่างของคุณจะเป็น:

http หรือ https://yourdomain.com/wc-api/v2/products/?oauth_consumer_key=ck_670ae128f1ebb1859ba03b2171f8ca7c

หวังว่านี่จะช่วยได้

person semir worku    schedule 10.11.2014