wp-net / WordPressPCL

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

Support wordpress.com sites #104

Open ThomasPe opened 6 years ago

ThomasPe commented 6 years ago

Hosted blogs on wordpress.com at least partly support the new REST API V2. For this package to work we would need probably flag hosted vs. selfhosted since the API URL structure is slightly different:

https://public-api.wordpress.com/wp/v2/sites/$wpcom_site/posts vs https://$wphosted_site/wp-json/wp/v2/posts

Marneus77 commented 6 years ago

defaultPath just has to be empty for sites hosted by wordpress.com. It could be an optional parameter for the client constructor, to keep the compatibility with older releases.

ThomasPe commented 6 years ago

Good suggestion, I've changed the client accordingly. Can you try if that's how you would expect it to work?

Marneus77 commented 6 years ago

Hi, the client seems to be working, I can get a category. A new error arose: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IList`1[System.Object]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path '[0].meta.amp_status', line 1, position 1447.

I don't think it's related. I don't find a definition for "meta" in POSTS or PAGES...

Marneus77 commented 6 years ago

I solved it by changing Meta in Models.post and Models.page to "object" instead of iList or iEnumerable. It's for another ticket I think. (json had "meta":{"amp_status":""} ) Bottom line, the client is working great with defaultpath = "".

ThomasPe commented 6 years ago

Since today I'm seeing the same issue.

hbcondo commented 5 years ago

@ThomasPe, would you mind describing how you got WordPressPCL working on sites hosted on Wordpress.com? My understanding is that they do not provide access to wp-config.php which is required to modify after installing the JWT Authentication for WP REST API plugin. Thanks.

Marneus77 commented 5 years ago

@hbcondo I'm interested as well if you have a solution. I'm running without the plugin at the moment.

ThomasPe commented 5 years ago

Actually, I have not yet looked at authentication for wordpress.com accounts. As far as I can tell we would need to implement the authentication for wordpress.com separately since that probably won't work with the JWT Authentication plugin (as you've mentioned).

I guess that would be the best starting point: https://developer.wordpress.com/docs/oauth2/

I'm not sure if I'll have enough time to implement this in the next few days or weeks, but maybe someone else wants to take a shot at this.

hbcondo commented 5 years ago

I'm still interested in using the business account of WordPress.com for hosting so I emailed them about JWT and their response was JTW isn't allowed and Business sites use WordPress.com accounts for authentication even though I explained JWT would be used by a service and not actual users.

I like the idea of supporting different authentication plugins as that would support this issue

hbcondo commented 2 months ago

This is an old open issue that for me has been resolved as I've been successfully using WordPressPCL with a site hosted with WordPress.com for years now. Thanks for such an awesome library!!

ThomasPe commented 2 months ago

happy it works. can you explain how you did the auth part?

hbcondo commented 2 months ago

I installed the JWT Authentication for WP REST API plugin and defined JWT_AUTH_SECRET_KEY in the site's wp-config.php file.

WordPress.com's hosting features were updated signficantly since this issue was created in 2018. Now they provide SFTP/SSH and WP-CLI which made this easier to implement.