Stream JSON from Twitter
Old version: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=32187297" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=32187297</a><p>Post-Musk Twitter changes broke extraction of rest_id on &quot;verified&quot; accounts, easy fix<p><pre><code>            case $(uname) in :)
            ;;Linux)
            export X=$(ss -ptnl|sed -n &#x27;&#x2F;127.104.244.42:1&#x2F;{s&gt;.*,pid=&gt;&gt;;s&gt;,.*&gt;&gt;p;}&#x27;)
            ;;NetBSD)
            export X=$(ps ax|sed -n &#x27;&#x2F;stunnel -fd 0$&#x2F;s&#x2F; .*&#x2F;&#x2F;p&#x27;)
            esac   
            test ! $X||kill $X
            stunnel -fd 0 &lt;&lt; eof 
            foreground=no
            [ twitter.com ]
            accept=127.104.244.42:1
            client=yes
            connect=104.244.42.1:443
            options=NO_TICKET
            options=NO_RENEGOTIATION
            renegotiation=no
            sni=
            sslVersion=TLSv1.3
    ;--------------------------------  TWITTER&#x27;S GRAPHQL      
    eof
            test $# = 1||exec echo usage: $0 screen_name
            CR=$(printf &#x27;\r&#x27;);
            ADDCR()
            {
            sed &quot;&#x2F;^------&#x2F;s&#x2F;.*&#x2F;&#x2F;;s&#x2F; *&#x2F;&#x2F;;s&#x2F; *$&#x2F;&#x2F;;s&#x2F;$&#x2F;$CR&amp;&#x2F;&quot; 
            }
            SCREEN_NAME=$1
            COUNT=500
            HOST=&quot;host: twitter.com&quot;
            CONNECTION=&quot;connection: close&quot;
            CONTENT_TYPE=&quot;content-type: application&#x2F;json&quot;
            AUTHORISATION=&quot;authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA&quot;
            X_GUEST_TOKEN=&quot;x-guest-token: &quot;
            GT=$(
            ADDCR &lt;&lt; eof|nc -vvn 127.104.244.42 1 |sed -n &#x27;&#x2F;gt=&#x2F;{s&#x2F;.*gt=&#x2F;&#x2F;;s&#x2F;;.*&#x2F;&#x2F;p;}&#x27;;
            GET &#x2F;$SCREEN_NAME HTTP&#x2F;1.1
            $HOST
            $CONNECTION
    --------------------------------  RUBE      
    eof
            )
            echo &quot;x-guest-token: $GT&quot; &gt;&amp;2;
            REST_ID=$(
            x=$(echo x|tr x &#x27;\34&#x27;);
            ADDCR &lt;&lt; eof|nc -vvn 127.104.244.42 1|sed -n &quot;&#x2F;\&quot;rest_id\&quot;:&#x2F;s&#x2F;\&quot;rest_id\&quot;:\&quot;&#x2F;$x&#x2F;p&quot;|tr &#x27;\34&#x27; &#x27;\12&#x27;|sed &#x27;1d;s&#x2F;\&quot;.*&#x2F;&#x2F;&#x27;
            GET &#x2F;i&#x2F;api&#x2F;graphql&#x2F;mCbpQvZAw6zu_4PvuAUVVQ&#x2F;UserByScreenName?variables={"screen_name":"$SCREEN_NAME","withSafetyModeUserFields":true,"withSuperFollowsUserFields":true} HTTP&#x2F;1.1
            $HOST
            $CONTENT_TYPE
            $AUTHORISATION
            $X_GUEST_TOKEN $GT
            $CONNECTION
    --------------------------------  GOLDBERG      
    eof
            )
            echo &quot;rest_id: $REST_ID&quot; &gt;&amp;2;
            # 3. get usertweets
            ADDCR &lt;&lt; eof|nc -vvn 127.104.244.42 1 
            GET &#x2F;i&#x2F;api&#x2F;graphql&#x2F;3ywp9kIIW-VQOssauKmLiQ&#x2F;UserTweets?variables={"userId":"$REST_ID","count":$COUNT,"includePromotedContent":true,"withQuickPromoteEligibilityTweetFields":true,"withSuperFollowsUserFields":true,"withDownvotePerspective":false,"withReactionsMetadata":false,"withReactionsPerspective":false,"withSuperFollowsTweetFields":true,"withVoice":true,"withV2Timeline":true}&amp;features={"dont_mention_me_view_api_enabled":true,"interactive_text_enabled":true,"responsive_web_uc_gql_enabled":false,"vibe_tweet_context_enabled":false,"responsive_web_edit_tweet_api_enabled":false,"standardized_nudges_misinfo":false,"responsive_web_enhance_cards_enabled":false,"include_rts":true} HTTP&#x2F;1.1
            $HOST
            $CONTENT_TYPE
            $AUTHORISATION
            $X_GUEST_TOKEN $GT
            $CONNECTION
    --------------------------------  DEVICE      
    eof
            case $(uname) in :)
            ;;Linux)
            exec kill $(ss -ptnl|sed -n &#x27;&#x2F;127.104.244.42:1&#x2F;{s&gt;.*,pid=&gt;&gt;;s&gt;,.*&gt;&gt;p;}&#x27;)
            ;;NetBSD)
            exec kill $(ps ax|sed -n &#x27;&#x2F;stunnel -fd 0$&#x2F;s&#x2F; .*&#x2F;&#x2F;p&#x27;)
            esac</code></pre>