RESTful API - WooCommerce REST API请求因curl而失败

har*_*ryg 3 api rest restful-authentication woocommerce

我最近更新到WooCommerce 2.1的最新版本,其中包括一个新的RESTful API.我对cURL或RESTful API没有多少经验,但我认为我给它一个游戏.

我的网站是sergedenimes.com,我在服务器上设置了SSL.

如果我运行,curl https://sergedenimes.com/wc-api/v1我会得到一个很长的json输出,如下所示:

{
   "store":{
      "name":"Serge DeNimes",
      "description":"Original, Urban T-Shirts Of The Highest Quality by Oliver Proudlock",
      "URL":"http:\/\/sergedenimes.com",
      "wc_version":"2.1.2",
      "routes":{
         "\/":{
            "supports":[
               "HEAD",
               "GET"
            ],
            "meta":{
               "self":"http:\/\/sergedenimes.com\/wc-api\/v1\/"
            }
         },
         "\/customers":{ etc.....
Run Code Online (Sandbox Code Playgroud)

这表明api本身正在发挥作用.但是,当我传递使用身份验证的请求时:

curl https://sergedenimes.com/wc-api/v1/orders -u my_key:my_secret
Run Code Online (Sandbox Code Playgroud)

我得到了回应:

{
   "errors":[
      {
         "code":"woocommerce_api_authentication_error",
         "message":"Consumer Key is missing"
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我的语法是否正确?我已经在WP管理员下设置了我的密钥和秘密并传递了值,但它似乎认为我没有通过我的请求传递它.

有任何想法吗?

Ger*_*ard 6

确保在WooCommerce - >设置 - >结帐时启用了安全结账选项.如果启用了该选项,它将仅使用基本身份验证.

  • 我还编写了这个方便的客户端库,以便更轻松地与API进行交互http://gerhardpotgieter.com/2014/02/10/woocommerce-rest-api-client-library/ (2认同)