Action
Post to Micro.blog w/draft
UPDATES
12 months ago
better title for the script
Update to the original Post to Micro.blog script. First time running this action, you will need to provide an app token generated from your profile at Micro.blog
When you run this script you’ll get a question if the post is a draft. If so, you’ll be redirected to the edit-screen, otherwise the post is published.
Steps
-
script
/* post to Micro.blog hosted account using Micropub API */ // First run, you will be prompted for // App Token. Generate tokens on the Micro.blog // Account page var credential = Credential.create("Micro.blog", "Insert Micro.blog app token generated on Micro.blog account page."); credential.addTextField("apptoken", "App Token"); credential.authorize(); var appToken = credential.getValue("apptoken"); // Does it draft? let p = Prompt.create(); p.addSwitch("select-post-status", "Is it a draft", false); p.addButton("OK"); if(p.show()){ if (p.fieldValues["select-post-status"] == true) { var poststatus = "draft"; } else { var poststatus = "publish"; } } // Setup micro.blog API and content var endpoint = "https://micro.blog/micropub" var content = draft.content // create and post HTTP request var http = HTTP.create(); var response = http.request({ "url": endpoint, "method": "POST", "encoding": "form", "data": { "h": "entry", "content": content, "post-status": poststatus }, "headers": { "Authorization": "Bearer " + appToken } }); var results = JSON.parse(response.responseText); if(poststatus != "draft"){ app.openURL(results.url); }else{ app.openURL(results.edit); } console.log("Response: " + response.statusCode); if (response.statusCode != 200 && response.statusCode != 202) { context.fail(); }
Options
-
After Success Nothing Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.