Can I use the REST API for a site hosted on WordPress.com [closed]

十年热恋 提交于 2020-01-02 05:21:07

问题


I have a blog hosted on WordPress.com. When I try to make a GET request to retrieve the posts I get a 'Not Found' html page.

https://alexkojin.wordpress.com/wp-json/wp/v2/posts

I know about the legacy public API but it doesn't allow me to retrieve private posts.

Can I use the REST API for site hosted on WordPress.com?


回答1:


On the WordPress.com platform the REST API is actually hosted and structured at https://public-api.wordpress.com/wp/v2 for all sites. In addition, there's a /sites/ endpoint that will namespace your specific site.

For example, the root endpoint for your site would be https://public-api.wordpress.com/wp/v2/sites/alexkojin.wordpress.com/. The other endpoints behave the same way as they would on a self hosted platform.

For example, your pages would be found under https://public-api.wordpress.com/wp/v2/sites/alexkojin.wordpress.com/pages

You can find more information at https://developer.wordpress.com/2016/11/11/wordpress-rest-api-on-wordpress-com/ including how to setup OAuth2 (which will be required to access private posts).



来源:https://stackoverflow.com/questions/48589954/can-i-use-the-rest-api-for-a-site-hosted-on-wordpress-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!