【发布时间】:2014-03-21 11:25:44
【问题描述】:
我最近更新到最新版本的 WooCommerce 2.1,其中包括 new 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.....
这表明 api 本身正在工作。但是,当我传递使用身份验证的请求时:
curl https://sergedenimes.com/wc-api/v1/orders -u my_key:my_secret
我得到这个回应:
{
"errors":[
{
"code":"woocommerce_api_authentication_error",
"message":"Consumer Key is missing"
}
]
}
我的语法正确吗?我已经在 WP 管理员下设置了我的密钥和秘密并传递了值,但似乎认为我没有通过我的请求传递它。
有什么想法吗?
【问题讨论】:
-
我卡在你的同一个地方。可以分享完整的网址吗?
-
完整的 URL 在我的问题中。 @Gerhard 的回答已经解决了。如果您仍然遇到问题,如果您的服务器难以处理在标头中发送的身份验证(仅限基本身份验证),则将身份验证凭据作为 GET 参数传递可能是一种解决方法。例如。
https://example.com/wc-api/v1/orders?consumer_key=ck_7xxxxx&consumer_secret=cs_7xxxxxx -
另外,Postman 是一个方便的工具,用于测试 API 而无需摆弄 curl 等。
标签: api rest woocommerce restful-authentication