微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Wordpress.com端点中使用 Node WPAPI?

如何解决如何在 Wordpress.com端点中使用 Node WPAPI?

我正在研究如何将 Node WPAPIwordpress.com 托管的博客一起使用。

const wp = new WPAPI({
  endpoint: 'https://MYSITE.wordpress.com/wp-json'
})
const posts = await wp.posts().get()
console.log(`posts:`,posts)

但我收到“未找到”错误(如果我将 wordpress 隐私设置为“私人”,则不会出现任何错误!)。

我习惯于在 https://public-api.wordpress.com/rest/v1.1/sites/MYSITE.wordpress.com/postswordpress REST API 交互,但 /wp-json 路由似乎不可用。

怎么办?

更新

似乎 v2 API 端点是 https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com 但现在我收到此错误

{ code: 'rest_no_route',message: 'No route was found matching the URL and request method.' }

解决方法

我很近,终点是:

https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com/{resource}

例如:

https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com/posts

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。