问题
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