评论未使用 xml-rpc wp.newComment php 发布

发布于 2024-11-25 06:38:20 字数 1103 浏览 1 评论 0原文

我有一个这样的代码。

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-12-02 06:38:20

老兄,删除数组属性中的所有“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 ;)]

浮光之海 2024-12-02 06:38:20

您在请求中使用了无效参数。
Wordpress XML-RPC_wp 文档列出了以下对 wp.newComment 请求有效的参数:

Parameters

    int blog_id
    string username
    string password
    int post_id
    struct comment
        int comment_parent
        string content
        string author
        string author_url
        string author_email 

以下代码应该足以通过 xmlrpc 在 wordpress 3.3.5 (XML-RPC_wp api v3.1) 上发布新评论:

<?     
include('IXR_Library.php.inc');
    $client = new IXR_Client('http://myblog.com/xmlrpc.php');

    $time = date("Ymd")."T".date("H:i:s")."Z";

    $post_id = "630";

    $data = array(
    'author' => 'test_author',
    'author_email' => '[email protected]',
    'author_url' => 'http://www.scroogle.org',
    'content' => 'Comentario Teste <a href="http://www.scroogle.org">scroogle.org</a>',
    'date' => $time,
    'approved' => 1,
    );


    if (!$client->query('wp.newComment','', '','',$post_id, $data)) {
    die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
    }
    $result = $client->wp_insert_comment($data);
    print_r($result);
?>

注意:为了通过 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:

Parameters

    int blog_id
    string username
    string password
    int post_id
    struct comment
        int comment_parent
        string content
        string author
        string author_url
        string author_email 

The following code should be enough to post a new comment on wordpress 3.3.5 (XML-RPC_wp api v3.1) via xmlrpc:

<?     
include('IXR_Library.php.inc');
    $client = new IXR_Client('http://myblog.com/xmlrpc.php');

    $time = date("Ymd")."T".date("H:i:s")."Z";

    $post_id = "630";

    $data = array(
    'author' => 'test_author',
    'author_email' => '[email protected]',
    'author_url' => 'http://www.scroogle.org',
    'content' => 'Comentario Teste <a href="http://www.scroogle.org">scroogle.org</a>',
    'date' => $time,
    'approved' => 1,
    );


    if (!$client->query('wp.newComment','', '','',$post_id, $data)) {
    die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
    }
    $result = $client->wp_insert_comment($data);
    print_r($result);
?>

Note: In order to post anonymous comments via xmlrpc you'll need WordPress – Anonymous XMLRPC Comments Plugin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文