帮助,我正在尝试使用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;
解决方法
虽然技术上有效的语法,但它没有按照你的想法.
'custom_fields' => { { "key" => "height","value" => 750 } },
大致等同于:
'custom_fields' => { 'HASH(0x881a168)' => { "key" => "width",
这肯定不是你想要的. (0x881a168部分会有所不同;它实际上是存储hashref的地址.)
我不确定自定义字段的正确语法是什么.你可以试试
'custom_fields' => [ { "key" => "height","value" => 750 } ],
这会将custom_fields设置为哈希数组.但这可能不对.这取决于send_request期望的内容.