【发布时间】:2012-08-02 09:00:29
【问题描述】:
这是我的电话:
result = blog.call('wp.newPost',
1,
'user',
'pw',
{
'post_type' => 'post',
'post_content' => entry[3],
'post_name' => entry[2].downcase.split(" ").join("-"),
'comment_status' => 'closed',
'pinged' => 'closed',
'post_status' => 'publish',
'post_title' => entry[2],
'terms' => ['category' => 9]
})
这将返回一个错误,即此帖子类型 post 不支持给定 category 的分类法之一 - 好吧,每个帖子都应该有一个类别,所以我认为我的 ruby 格式不正确。 API 要求一个数组,其中分类法作为键,其 ID 作为值,我想我已经在这里完成了。
这适用于 v3.4 - here is the documentation on wp.newPost
【问题讨论】:
-
很难在没有看到
blog.call方法的情况下发表评论。但是,API 文档要求一个以分类名称为键的数组和一个以术语 ID 为值的数组。所以,如果9是您要分配给帖子的术语的ID,我猜它应该是'terms' => ['category' => [9]]。 -
另外,我对 Ruby 不熟悉,但我认为您不能使用该语言指定数组键,因此您可能需要使用哈希:
'terms' => {'category' => [9]} -
@RichardM 实际上,这两个都不起作用-我确实认为这与数组格式有关。第一个产生了相同的错误,第二个产生了 302 found 错误(它基本上完全忽略了该行)