尝试检索私人帖子时,我收到{“ code”:“ rest_forbidden”,“ message”:“对不起,您不允许这样做。”,“ data”:{“ status”:401}}

时间:2019-10-04 18:17:25

标签: wordpress wordpress-rest-api

尝试使用REST API检索帖子:

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

我已通过管理员身份验证,该帖子已发布给我。我已经分配了所有管理员权限。我可以检索非私人帖子,但是一旦将其标记为私人,我就会收到错误消息作为回应

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

还有什么我需要做的事情才能允许检索私人帖子?

-编辑:我通过JWT进行了身份验证,但我的回复返回了所有公开帖子,没有私人帖子

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 个答案:

答案 0 :(得分:0)

我认为这是预期的行为[至少我可以在自己的网站上确认同一件事]。您可能必须创建自己的路线才能访问私人帖子。