Well, before I knew it, I have been Posting all night for 1890 days. During this difficult night, I have frequent insomnia and even dream about when there will be a regular Posting function, so that I can have a good sleep 😰😰

How to achieve this function, what ideas

  1. That is the official support for 🥺
  2. You just have to figure it out
    1. Write a script (it’s useless, it’s not worth it to leave it on all day)
    2. (We can adjust the interface, after all, we are ALL API call engineers)

The body of the

  • First, prepare the article we are going to publish
    • Required optionsIt all has to be filled out. Save it to draft

  • Publish the article and then capture the packet
    • Here, we see an important interface
    • The red box is the post (Focus on)
    • Below the red box is the jump to Post Success page (Don't use)

  • Next, take a look at what the interface does

    • Let’s look at Headers, let’s focus on itCookieSessionid in the sessionid, nothing else

    • How to get a sessionid (sessionid)

    • Now let’s look at the parameters

    • To explain the parameters:
      • Draft_id this is the article Id (How to get the picture below)

      • Other parameters for nowNo dice
  • How do you know if it was sent successfully

    • Only the response result contains"err_no": 0It’s a success

The focus has been finished, how to achieve a scheduled release, each big guy in the mind should have their own ideas

🍀🍀 Time to write code

  • Train of thought

    • Set a scheduled task
    • Callback interface
    • finished
  • Scripting (big drawbacks)

    • Write a shell script, save it to Linux, and add a scheduled task
    #! /bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH curl --location --request POST 'https://api.juejin.cn/content_api/v1/article/publish' \ --header 'Content-Type: application/json' \ --header 'Cookie: Sessionid = your sessionid; '\ - data - raw' {" draft_id ":" your article ID ", "sync_to_org" : false, "column_ids" : [] }' echo "----------------------------------------------------------------------------" endDate=`date +"%Y-%m-%d %H:%M:%S" 'Successful" ★[$endDate] Successful" echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -"Copy the code
    • Adding a Scheduled Task
    // edit the scheduled task vim /etc/crontab// add the line * * * * * user-name command to be executed // * * * * * // command to be executed script path // For example, run the following command: // 0 3 * * * root/XXXXCopy the code
  • Code (Java as an example)

/** * use hutool * 
      
       cn. Hutool 
      
       hutool-all
       * The < version > 4.6.10 < / version > * < / dependency > * /

public class Publish {

    static DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    static ScheduledThreadPoolExecutor executor;

    public static void main(String[] args) {
        if (args.length < 1) {
            System.out.println("Parameter example: Java - cp XXXX. Jar. Com yeting. Juejin. Publish sessionid article ID - > release time article ID - > release time");
            System.out.println("Sessionid: is the nugget sessionID");
            System.out.println("Article ID-> Date of publication: -> is delimiter");
            return;
        }

        String sessionId = args[0];

        executor = new ScheduledThreadPoolExecutor(
                args.length - 1,
                ThreadFactoryBuilder.create().setNamePrefix("publish-").build()
        );
        // Iterate over all tasks
        for (int i = 1; i < args.length; i++) {
            String line = args[i];
            // Capture the ID and publication time of the article
            String[] split = line.split("- >");
            String draftId = split[0];
            LocalDateTime publishTime = LocalDateTime.parse(split[1], dateFormat);
            LocalDateTime now = LocalDateTime.now();
            // Calculate how many minutes are left to publish
            Duration duration = Duration.between(now, publishTime);
            long delay = duration.toMinutes();
            // Give it to the thread pool for scheduled execution
            executor.schedule(() -> {
                Boolean publish = publish(draftId, sessionId);
                if (publish) {
                    System.out.println("Article ID:" + draftId + "Successful release");
                } else {
                    System.err.println("Article ID:" + draftId + "Release failed");
                }
            }, delay, TimeUnit.MINUTES);
            System.out.println("Parse successful, article ID:" + draftId + "Will be at:" + publishTime.format(dateFormat) + "Release"); }}public static Boolean publish(String draftId, String sessionId) {
        Map<String, String> headers = new HashMap<>(20);
        headers.put("Host"."api.juejin.cn");
        headers.put("Connection"."keep-alive");
        headers.put("sec-ch-ua"."\" Not; A Brand\"; v=\"99\", \"Google Chrome\"; v=\"91\", \"Chromium\"; v=\"91\"");
        headers.put("sec-ch-ua-mobile"."? 0");
        headers.put("Accept"."* / *");
        headers.put("Origin"."https://juejin.cn");
        headers.put("Sec-Fetch-Site"."same-site");
        headers.put("Sec-Fetch-Mode"."cors");
        headers.put("Sec-Fetch-Dest"."empty");
        headers.put("Referer"."https://juejin.cn/");
        headers.put("Accept-Language"."zh-CN,zh; Q = 0.9");
        headers.put("Cookie"."sessionid=" + sessionId + "; ");

        Map<String, Object> body = new HashMap<>(6);
        body.put("draft_id", draftId);
        body.put("sync_to_org".false);
        body.put("column_ids", Collections.emptyList());

        String res = HttpUtil.createPost("https://api.juejin.cn/content_api/v1/article/publish")
                .headerMap(headers, true)
                .body(JSONUtil.toJsonStr(body))
                .execute()
                .body();
        return "0".equals(JSONUtil.parseObj(res).getStr("err_no")); }}Copy the code
  • I’m too lazy to do anythingThen use the ready-made ones
    • 👉🏻 Portal 👈🏻
    • Be sure to like !!!!!!!! when you’re done








In order not to be abandoned by The Times, I also posted a picture of a girl