Post to Micro.blog

Posted by agiletortoise, Last update over 1 year ago

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.

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();
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.