Post comments to Known with Micropub

Last year I wanted to backup a friend's instagram account, and chose a local Known instance as target.

Posting "normal" text and photo posts into a blog is standardized now: Simply use Micropub with a client of your choice. I wrote shpub in that time, which is a micropub client for the shell, neatly packaged up into a single .phar file.

With Known and shpub in place, I wrote a script that regularly checked the Instagram account site, extracted text, image and geo coordinates of new posts and pushed them into Known.

One thing was missing: Social reactions - comments and likes.

So I sat down and extended Known's micropub plugin to support receiving likes, comments and RSVPs. At the time this patch got merged, my instagram backup project was sunken into deep sleep and I never got around making the script import the reactions as well.

Some weeks ago I wanted to write a blog post about the comments-via-micropub functionality and saw that it .. did not work at all. My patch had a serious flaw (! at the wrong place, a debug leftover) and nobody had noticed it :/ So now that problem is patched in latest git and will land in the version that follows Known 0.99.

Usage

Instead of sending a h=entry micropub post type, h=annotation with a couple of extra parameters has to be sent:

Post a comment

$ curl -X POST\
 -H 'Content-Type: application/x-www-form-urlencoded'\
 -H 'Authorization: Bearer deadbeefcafe'\
 -d 'h=annotation'\
 -d 'url=http://example.org/some-blog-post'\
 -d 'type=reply'\
 -d 'username=barryf'\
 -d 'userurl=http://example.org/~barryf'\
 -d 'userphoto=http://example.org/~barryf/avatar.jpg'\
 -d "content=There is a typo in paragraph 1 - 'Fou' should be 'Foo'"\
 'http://example.org/micropub/endpoint'

Alternatively you can use shpub:

$ ./bin/shpub.php x annotation\
 -x url=http://example.org/some-blog-post\
 -x type=reply\
 -x username=barryf\
 -x userurl=http://example.org/~barryf\
 -x userphoto=http://example.org/~barryf/avatar.jpg\
 -x content="There is a typo in paragraph 1. 'Fou' should be 'Foo'"

Post a like

$ curl -X POST\
 -H 'Content-Type: application/x-www-form-urlencoded'\
 -H 'Authorization: Bearer deadbeefcafe'\
 -d 'h=annotation'\
 -d 'url=http://example.org/some-blog-post'\
 -d 'type=like'\
 -d 'username=barryf'\
 -d 'userurl=http://example.org/~barryf'\
 -d 'userphoto=http://example.org/~barryf/avatar.jpg'\
 'http://example.org/micropub/endpoint'

Post a RSVP

$ curl -X POST\
 -H 'Content-Type: application/x-www-form-urlencoded'\
 -H 'Authorization: Bearer deadbeefcafe'\
 -d 'h=annotation'\
 -d 'url=http://example.org/some-blog-post'\
 -d 'type=like'\
 -d 'username=barryf'\
 -d 'userurl=http://example.org/~barryf'\
 -d 'userphoto=http://example.org/~barryf/avatar.jpg'\
 -d 'content=yes'\
 'http://example.org/micropub/endpoint'

Written by Christian Weiske.

Comments? Please send an e-mail.