I receive {“code”:“rest_forbidden”,“message”:“Sorry, you are not allowed to do that.”,“data”:{“status”:401}} when trying to retrieve a private post

人盡茶涼 提交于 2021-02-04 21:37:17

问题


Trying to retrieve a post using the REST API:

http://localhost/mysite/wp-json/wp/v2/posts/605.

I am authenticated as administrator and the post was published my me. I have all the administrator rights assigned. I can retrieve non-private posts but as soon as I mark them private I get an error as a response

{"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}}

Is there anything else I should be doing to allow retrieval of private posts ?

-- Edit: I am authenticated via JWT but my response returns all public posts and none of the private ones

if (await client.IsValidJWToken())
                {                  
                    var queryBuilder = new PostsQueryBuilder();
                    queryBuilder.PerPage = 8;
                    queryBuilder.Page = 1;
                    queryBuilder.Embed = true;
                    //queryBuilder.Categories = new int[] { category };
                    queryBuilder.Statuses = new Status[] { };

                    try
                    {
                        var response = await client.Posts.Query(queryBuilder);
                        var r = response;

                    }
                    catch (Exception e)
                    {
                        var m = e.Message;

                    }

回答1:


I think this is the expected behavior [at least I can confirm the same thing on my sites]. You'll probably have to create your own route to access the private posts.



来源:https://stackoverflow.com/questions/58241435/i-receive-coderest-forbidden-messagesorry-you-are-not-allowed-to-do-t

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