帮助,我正在尝试使用metaweblogAPI over XMLRPC使用以下perl脚本在我的wordpress博客中使用自定义字段创建新帖子,但自定义字段似乎存在问题。似乎只发布了第二个自定义字段(宽度)。无法获得正确发布的“高度”。当我添加另一个字段时,我得到“匿名哈希中的奇数元素数”错误。这必须是简单的事情 - 有人会善意地检查我的语法吗?感谢。
#!/usr/bin/perl -w
use strict;
use RPC::XML::Client;
use Data::Dumper;
my $cli=RPC::XML::Client->new('http://www.sitename.com/wp/xmlrpc.php');
my $appkey="perl"; # doesn't matter
my $blogid=1; # doesn't matter (except blogfarm)
my $username="Jim";
my $passwd='_____';
my $text=<<'END';
This is the post content...
You can also include html tags...
See you!
END
my $publish=0; # set to 1 to publish, 0 to put post in drafts
my $resp=$cli->send_request('metaWeblog.newPost',
$blogid,
$username,
$passwd,
{
'title' => "this is doodoo",
'description' => $text,
'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},
},
$publish);
exit 0;
答案 0 :(得分:13)
虽然技术上有效的语法,但它没有按照你的想法进行。
'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},
大致相当于:
'custom_fields' => {
'HASH(0x881a168)' => { "key" => "width", "value" => 750 }
},
这当然不是你想要的。 (0x881a168部分会有所不同;它实际上是存储hashref的地址。)
我不确定自定义字段的正确语法是什么。你可以尝试
'custom_fields' => [
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
],
将custom_fields设置为哈希数组。但这可能不对。这取决于send_request
期望的内容。