How to automate Ghost/Medium cross-posting via ZapiersteemCreated with Sketch.

in python •  8 months ago

With this blog, I'm eager to automate a lot of the tedium that comes with cross-posting to other platforms. Medium was first on the docket due to its popularity - and I quickly came across this fantastic article by Christoph Michel on how he automates the process.

(NOTE: automatic Steemit crossposting is next on the docket)

At the time of writing, the typenil blog uses Ghost for publishing content, so I had to do things a little differently than Christoph. I also wanted to sidestep the need to host the automation code, myself, so using Ghost's built-in Zapier integration made the most sense.

(NOTE: you can use the repo ghost-crosspost-medium
without Ghost or Zapier, but it was originally written with these in mind)

Before we get started on anything, we'll need an integration token from Medium. Make sure you're logged into Medium and go to the "Integration tokens" section of your settings.


Get that integration token - you'll need it as a parameter as we head over to Zapier. Sign up or login to Zapier and "Make a Zap!"


Select Ghost as your trigger app; you can search for it if it's not right there. If you haven't connected Ghost before, Zapier will walk you through it.


After Ghost is connected and selected, select "New Story" as the Ghost trigger.


When asked to select the status for the trigger, pick "Published" unless you have reasons to go with something else.


Next stage is selecting the action app. We're going with "Code" and "Run Python" (which is, unfortunately, Python 2.7).



Configuring the template is where the real setup happens. The required fields for my script are "integrationToken", "content", "title", and "canonicalUrl", but including "tags" is also adviseable.

"integrationToken" is the token you set up in Medium earlier; it'll be the same for all requests.

Each of the other fields correspond to values provided by Ghost. This will be easiest if you already have at least 1 post up (even if you post it just for this exercise) since Zapier will show you an example of the input.


Input Name Ghost Name
title Title
canonicalUrl URL
content HTML Formatted Content
tags Tags Slug

The order you add the items in doesn't matter - and if you're a more advanced user, any additional fields you specify will also be passed on to the Medium call (see the Medium post API docs for more info).


Once the inputs are set up, it's time for the code, itself. I've set up a repository for this project on my GitHub under ghost-crosspost-medium, but to get this working on Zapier you just have to copy and paste this file.

(NOTE: Omitting the code here, as I can't get Steemit to format it correctly.)

Take the code from the link above and paste it into the "Code" section at the bottom of the Zapier template page.


By this point, you should be good to wrap it up. Scroll to the bottom and continue. You'll then have the opportunity to test the connection.


If everything checks out, click "Finish" and turn on your Zap!


If you're having problems, feel free to open an issue on that GitHub repo. The error messages returned from the Medium API are incredibly vague, so debugging it can be a major pain.

In the future, I'd like to add automatic relative link resolution like Christoph includes in his tutorial. For Ghost, this doesn't appear to be necessary; relative links get resolved by the time they hit Zapier.

Prefer to catch my posts elsewhere?

Originally published on my blog:
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!