API::Medium - Talk with medium.com using their REST API
version 0.902
use API::Medium; my $m = new({ access_token=>'your_token', }); my $hash = $m->get_current_user; say $hash->{id}; my $url = $m->create_post( $user_id, $post ); my $other_url = $m->create_publication_post( $publication_id, $post );
It's probably a good idea to read the Medium API docs first, especially as the various data structures you have to send (or might get back) are not documented here.
See example/hello_medium.pl for a complete script.
Not implemented yet, mostly because medium only support the "web server" flow and I'm using API::Medium for an installed application.
API::Medium
Go to your settings, scroll down to "Integration tokens", and either create a new one, or pick the one you want to use.
my $m = API::Medium->new({ access_token => $token, });
Create a new API client. You will need to pass in your $token, see above on how to get it. Please make sure no not leak your Integration Token. If you do, anybody who has it can take over your Medium page!
$token
my $data = $m->get_current_user;
Fetch the User "object".
You will need this to get the user id for posting. Depending on your app you might want to store your id in some config file to save one API call.
id
Not implemented yet. Listing the user's publications
/users/{{userId}}/publications
Not implemented yet. Fetching contributors for a publication.
/publications/{{publicationId}}/contributors
my $url = $m->create_post( $user_id, $post_data );
Create a new post. If you pass in bad data, Medium will probably report an error.
publishStatus is set to 'draft' unless you pass in another value.
publishStatus
my $url = $m->create_publication_post( $publication_id, $post_data );
Create a new post under a publication. You will need to figure out the publication_id by calling the API from the commandline (until publications is implemented.)
publications
If you pass in bad data, Medium will probably report an error.
OAuth2 Login
Get a new access_token from refresh_token
contributors
Thanks to Dave Cross for starting Cultured Perl, which prompted me to write this module so I can auto-post blogposts from my private blog to medium.
Thomas Klausner <domm@plix.at>
This software is copyright (c) 2016 - 2021 by Thomas Klausner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install API::Medium, copy and paste the appropriate command in to your terminal.
cpanm
cpanm API::Medium
CPAN shell
perl -MCPAN -e shell install API::Medium
For more information on module installation, please visit the detailed CPAN module installation guide.