我的 wordpress wp-api 测试数据遗漏了什么? [英] What am I missing from my wordpress wp-api test data?
问题描述
我正在使用 wp-api 进行测试,顺便说一下,我很高兴使用它.这是我所做的.
- 安装了 wp-api 并验证我可以使用 cURL 从网站获取
- 安装了基本身份验证,为此测试创建了一个编辑级帐户.
- 我尝试在 chrome 中使用 cURL 和 Postman 更新帖子.我的标题:-内容类型:应用程序/javascript- 文件中的数据我不确定是否还有其他我遗漏的标题.cURL 和 postman 都为我处理基本身份验证中的用户名和密码.
我的 JSON
<代码>{"title":"你好,更新的世界!","content_raw":"你好,内容更新.","日期":"2013-04-01T14:00:00+10:00"}
直接来自 wp-api 文档
我不断收到的错误是
<预><代码>[{"code": "json_missing_callback_param","message": "缺少参数数据"}]查看github上的源代码,好像缺少一个必需的参数
根据 documentation 标题和内容 raw 似乎是唯一的必填字段.如果您有任何建议,我很想知道我缺少什么.谢谢.
这是我使用 PHP/cURL 调用本地 WP-API 的代码:
$endpoint = 'http://localhost/my-site/wp-json/wp/posts';$用户名 = '测试用户';$password = '测试通过';$数据=数组('标题' =>$post_title,'content_raw' =>$post_content,'状态' =>'发布',);$json_data = json_encode($data);$ch = curl_init($endpoint);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);curl_setopt($ch, CURLOPT_HTTPHEADER, 数组('内容类型:应用程序/json','内容长度:'.strlen($json_data),));$result = json_decode(curl_exec($ch));
要更新这篇文章,我会将我的数据更改为:
$data = 数组('ID' =>$post_id,'标题' =>$new_title,'content_raw' =>$new_content,);
ID 是更新时的必填字段.
I am testing out using wp-api, I am very excited to use this by the way. Here is what I have done.
- installed wp-api and verified that I can get from the website using cURL
- Installed basic authentication, created an editor level account for this testing.
- I have tried to update a post using cURL and Postman in chrome. my headers: -Content-Type: application/javascript -data in a file I am not sure if there are other headers that I am missing. Both cURL and postman handle username and password in basic authentication for me.
my JSON
{
"title":"Hello Updated World!",
"content_raw":"Howdy updated content.",
"date":"2013-04-01T14:00:00+10:00"
}
straight from the examples in wp-api docs
the error I keep getting is
[
{
"code": "json_missing_callback_param",
"message": "Missing parameter data"
}
]
Looking at the source code on github it looks like a required parameter is missing
according to the documentation title and content raw seem to be the only required fields. I would love to know what I am missing if you have any suggestion. Thanks.
Here's the code I use to call a local WP-API with PHP/cURL:
$endpoint = 'http://localhost/my-site/wp-json/wp/posts';
$username = 'test-user';
$password = 'test-pass';
$data = array(
'title' => $post_title,
'content_raw' => $post_content,
'status' => 'publish',
);
$json_data = json_encode($data);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json_data),
));
$result = json_decode(curl_exec($ch));
To update this post, I would change my data to:
$data = array(
'ID' => $post_id,
'title' => $new_title,
'content_raw' => $new_content,
);
ID is a required field when updating.
这篇关于我的 wordpress wp-api 测试数据遗漏了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!