Drafts Action Directory

Post to Micro.blog

Posted by agiletortoise, Last updated: 2018-05-27 15:44:18 UTC

Post to a Micro.blog hosted account. After installing, generate an app token on your Micro.blog account page. The first time you run the action, you will be prompted to add the token.

Install

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");
    
    // 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
      },
      "headers": {
        "Authorization": "Bearer " + appToken
      }
    });
    
    console.log("Response: " + response.statusCode);
    
    if (response.statusCode != 200 && response.statusCode != 202) {
      context.fail();
    }
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.