wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
338 stars 129 forks source link

Cannot get "Unpublished" Post using GetByID #173

Closed SocialNetUsr closed 5 years ago

SocialNetUsr commented 5 years ago

Hi to all,

I'm trying to publish an unpublished post but the GetByID returns "Sorry, you are not allowed to do that." After some investigation i founded that the plugin cannot get posts that are in unpublished status. Any ideas??

var post = await client.Posts.GetByID(9999); post.Status = Status.Publish; post.Date = DateTime.Now; var updatedPost = await client.Posts.Update(post);

ThomasPe commented 5 years ago

Yes, you need to have valid JWT token for an authorized user to get unpublished posts.

SocialNetUsr commented 5 years ago

i'm using the below command which returns true. What else can i check ?? await client.IsValidJWToken();

ThomasPe commented 5 years ago

that should technically do it. Are you using a user that has the correct permissions to access unpublished posts?

SocialNetUsr commented 5 years ago

my user has Administrator role i have try almost all available methods without luck

Also in wp-admin/edit.php i can see the unpublished posts

polushinmk commented 5 years ago

@SocialNetUsr try

var post = await client.Posts.GetByID(9999, useAuth: true);
SocialNetUsr commented 5 years ago

bloody great, it's working!!! I didn't check this constructor.... Thanks all for the help!!!