Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 799 forks source link

Publicize / WPCOM API: I can not add publicize connection though API. #24480

Open uvkoladiya opened 2 years ago

uvkoladiya commented 2 years ago

Impacted plugin

Jetpack

Steps to Reproduce

I have tried to add new connection through "https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/publicize-connections/" here need "keyring_connection_ID". and this key i can only retrieve if we have added the publicized connection.

A clear and concise description of what you expected to happen.

No response

What actually happened

I have tried to add new connection through "https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/publicize-connections/" here need "keyring_connection_ID". and this key i can only retrieve if we have added the publicized connection.

Other information

No response

Operating System

Windows

OS Version

No response

Browser

Chrome/Chromium

Browser Version(s)

No response

jeherve commented 2 years ago

If you want to add a new connection, you'll have to use different endpoints. First you'll need to create a Keyring connection, and then use this endpoint to create a new connection: https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/publicize-connections/new/

To create and manage Keyring connections, I would recommend looking at the different keyring endpoints you can get in the API console here: https://developer.wordpress.com/docs/api/console/

I hope this helps!

uvkoladiya commented 2 years ago

How to add a keyring connection? Do you mean manually?

jeherve commented 2 years ago

Those things aren't really meant to work outside of a WordPress environment so this may be a bit tricky to set up, but you can find more about Keyring here: https://developer.wordpress.com/?s=keyring

uvkoladiya commented 2 years ago

So basically we can not add publicize connection through API outside of a WordPress environment right?

pablinos commented 2 years ago

You probably can, although the Keyring connections are created using an OAuth flow, and will have people authenticate against the WordPress.com applications. If you look at a section of Calypso like https://wordpress.com/marketing/connections you'll see that we're doing all this via the API.

There is an initial request to get a connection URL, which the user is sent to. They'll be redirected back to wordpress.com, which will create the Keyring connection, and then redirect or perform some other action based on the context. We do have a version of this flow that works within the block editor for the Instagram Gallery Block, but that is only creating the Keyring connection. It should be fairly straightforward to extend that to create a Publicize connection though.

What are you trying to create a Publicize connection for? Could you have the user go through the existing flow for doing that?