评论未使用 xml-rpc wp.newComment php 发布
我有一个这样的代码。
<?php
include('IXR_Library.php');
$client = new IXR_Client('http://127.0.0.1/wordpress/xmlrpc.php');
$data = array(
'comment_post_ID' => 1,
'comment_author' => 'test_author',
'comment_author_email' => '[email protected]',
'comment_author_url' => 'http://test.limewebs.com',
'comment_content' => 'Test Content',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 1,
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => $time,
'comment_approved' => 1,
);
if (!$client->query('wp.newComment','', 'username','password','12',$data)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$result = $client->wp_insert_comment($data);
print_r($result);
?>
在上面的代码中,我将评论发布到 WordPress 网站,但内容(comment_content)没有发布。
I have a code like this.
<?php
include('IXR_Library.php');
$client = new IXR_Client('http://127.0.0.1/wordpress/xmlrpc.php');
$data = array(
'comment_post_ID' => 1,
'comment_author' => 'test_author',
'comment_author_email' => '[email protected]',
'comment_author_url' => 'http://test.limewebs.com',
'comment_content' => 'Test Content',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 1,
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => $time,
'comment_approved' => 1,
);
if (!$client->query('wp.newComment','', 'username','password','12',$data)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$result = $client->wp_insert_comment($data);
print_r($result);
?>
In the above code, I get my comment posted to WordPress site, but the content(comment_content) is not getting posted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
老兄,删除数组属性中的所有“comment_”前缀。在编写WpAPI 类时,我深入挖掘了 WP XMLRPC 的核心。参数永远不会按照正常人放置的顺序排列。使用的名称也不一致。这不是猜谜游戏。不确定时请务必查看 WP 核心代码...[或使用我的类;)]
Dude, remove all 'comment_' prefix to your array properties. Writing the WpAPI Class I dug deep in the heart of WP's XMLRPC. Parameters are always never in the order an normal person would put them. The names used are not consistent either. It's not a guessing game. Always look at the WP core code when not sure... [or use my Class ;)]
您在请求中使用了无效参数。
Wordpress XML-RPC_wp 文档列出了以下对 wp.newComment 请求有效的参数:
以下代码应该足以通过 xmlrpc 在 wordpress 3.3.5 (XML-RPC_wp api v3.1) 上发布新评论:
注意:为了通过 xmlrpc 发布匿名评论你需要 WordPress – 匿名 XMLRPC 评论插件
You're using invalid parameters on your request.
Wordpress XML-RPC_wp documentation lists the following parameters has valid for wp.newComment requests:
The following code should be enough to post a new comment on wordpress 3.3.5 (XML-RPC_wp api v3.1) via xmlrpc:
Note: In order to post anonymous comments via xmlrpc you'll need WordPress – Anonymous XMLRPC Comments Plugin