diff options
-rw-r--r-- | exitter.el | 229 |
1 files changed, 108 insertions, 121 deletions
@@ -28,12 +28,12 @@ (format "%s/onboarding/task.json" exitter-url-endpoint) exitter-url-token (format "https://api.twitter.com/oauth2/token")) -(setq exitter-agent-param "-A \"TwitterAndroid/10.10.0\"") -(setq exitter-tor-param "-x socks5://127.0.0.1:9150/") +(setq exitter-tor-param "-x socks5://127.0.0.1:9050/") (setq exitter-init-headers `( ("Content-Type" . "application/json") ("User-Agent" . "TwitterAndroid/10.10.0 (29950000-r-0) ONEPLUS+A3010/9 (OnePlus;ONEPLUS+A3010;OnePlus;OnePlus3;0;;1;2016)") + ;; ("User-Agent" . "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36") ("X-Twitter-API-Version" . "5") ("X-Twitter-Client" . "TwitterAndroid") ("X-Twitter-Client-Version" . "10.10.0") @@ -55,8 +55,7 @@ ;; (setq request-message-level -1) (defun exitter-get-access-token () - (let ((request-curl-options `(,exitter-agent-param)) - (oauth-consumer-key-secret + (let ((oauth-consumer-key-secret (base64-encode-string (format "%s:%s" exitter-oauth-consumer-key exitter-oauth-consumer-secret) @@ -80,27 +79,28 @@ (defun exitter-get-guest-token () (message "entering exitter-get-guest-token") - (let ((request-curl-options `(,exitter-agent-param))) - (request exitter-url-activate - :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token))) - :parser 'json-read - :type "POST" - :success (cl-function - (lambda (&key data &allow-other-keys) - (exitter-get-flow-token (alist-get 'guest_token data)))) - :error - (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) - (message "Got error: %S" error-thrown))) - ))) - -(defun exitter-get-flow-token (guest-token) - (message "entering exitter-get-flow-token") - (let ((request-curl-options `(,exitter-agent-param))) + (request exitter-url-activate + :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token))) + :parser 'json-read + :type "POST" + :success (cl-function + (lambda (&key data &allow-other-keys) + (exitter-login-flow-token (alist-get 'guest_token data)))) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))) + )) + +(defun exitter-login-flow-token (guest-token) + (message "entering exitter-login-flow-token") + (let ((headers `(,@exitter-init-headers + ("Authorization" . ,(format "Bearer %s" exitter-access-token)) + ("X-Guest-Token" . ,guest-token) + ))) (request exitter-url-task - :param '(("flow_name" . "login")) - :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token)) - ("Content-type" . "application/json") - ("X-Guest-Token" . ,guest-token)) + :params '(("flow_name" . "login") + ("lang" . "en")) + :headers headers :data (json-encode '(("flow_token" . nil) ("input_flow_data" . @@ -117,20 +117,23 @@ :type "POST" :complete (cl-function (lambda (&key response &allow-other-keys) - (let ((att - (request-response-header response "att")) - (data - (request-response-data response))) + (let* ((att + (request-response-header response "att")) + (data + (request-response-data response)) + (flow-token (alist-get 'flow_token data))) (unless (exitter-find-subtask data "LoginEnterUserIdentifier") (error "Subtask LoginEnterUserIdentifier not found")) ;; (pp data) ;; (message "flow-token: %s\natt: %s" ;; (alist-get 'flow_token data) ;; att) - (exitter-enter-username guest-token - (alist-get 'flow_token data) - att) - ))) + (when att + (setq headers + `(,@headers + ("att" . ,att) + ("cookie" . ,(format "att=%s" att))))) + (exitter-enter-username flow-token headers)))) :error (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) (message "Got error: %S" error-thrown))) @@ -147,97 +150,81 @@ (defun exitter-report-error (&rest args &key error-thrown &allow-other-keys) (message "Got error: %S" error-thrown)) -(defun exitter-enter-username (guest-token flow-token att) +(defun exitter-enter-username (flow-token headers) (message "entering exitter-enter-username") - (let ((request-curl-options `(,exitter-agent-param))) - (request exitter-url-task - :params '(("lang" . "en")) - :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token)) - ("Content-type" . "application/json") - ("X-Guest-Token" . ,guest-token) - ("att" . ,att) - ("cookie" . ,(format "att=%s" att))) - :data (json-encode - `(("flow_token" . ,flow-token) - ("subtask_inputs" . - [(("enter_text" . - (("suggestion_id" . nil) - ("text" . ,exitter-username) - ("link" . "next_link"))) - ("subtask_id" . "LoginEnterUserIdentifier"))]))) - :type "POST" - :parser 'json-read - :success (cl-function - (lambda (&key data &allow-other-keys) - (cond - ((exitter-find-subtask data "LoginEnterPassword") - (message "LoginEnterPassword") - (exitter-enter-password guest-token flow-token att)) - ((exitter-find-subtask data "LoginEnterAlternateIdentifierSubtask") - (message "LoginEnterAlternateIdentifierSubtask") - (exitter-enter-email guest-token flow-token att)) - (t (message "Cannot find any matching subtasks"))) - )) - :error - (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) - (message "Got error: %S" error-thrown))) - ))) - - -(defun exitter-enter-password (guest-token flow-token att) + (request exitter-url-task + :params '(("lang" . "en")) + :headers headers + :data (json-encode + `(("flow_token" . ,flow-token) + ("subtask_inputs" . + [(("enter_text" . + (("suggestion_id" . nil) + ("text" . ,exitter-username) + ("link" . "next_link"))) + ("subtask_id" . "LoginEnterUserIdentifier"))]))) + :type "POST" + :parser 'json-read + :success (cl-function + (lambda (&key data &allow-other-keys) + (cond + ((exitter-find-subtask data "LoginEnterPassword") + (message "LoginEnterPassword") + (exitter-enter-password flow-token headers)) + ((exitter-find-subtask data "LoginEnterAlternateIdentifierSubtask") + (message "LoginEnterAlternateIdentifierSubtask") + (exitter-enter-email flow-token headers)) + (t (message "Cannot find any matching subtasks"))) + )) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))))) + + +(defun exitter-enter-password (flow-token headers) (message "entering exitter-enter-password") - (let ((request-curl-options `(,exitter-agent-param))) - (request exitter-url-task - :params '(("lang" . "en")) - :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token)) - ("Content-type" . "application/json") - ("X-Guest-Token" . ,guest-token) - ("att" . ,att) - ("cookie" . ,(format "att=%s" att))) - :data (json-encode - `(("flow_token" . ,flow-token) - ("subtask_inputs" . - [(("enter_password" . - (("password" . ,exitter-password) - ("link" . "next_link"))) - ("subtask_id" . "LoginEnterPassword"))]))) - :type "POST" - :parser 'json-read - :success (cl-function - (lambda (&key data &allow-other-keys) - (print data) - )) - :error - (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) - (message "Got error: %S" error-thrown))) - ))) - -(defun exitter-enter-email (guest-token flow-token att) + (request exitter-url-task + :params '(("lang" . "en")) + :headers headers + :data (json-encode + `(("flow_token" . ,flow-token) + ("subtask_inputs" . + [(("enter_password" . + (("password" . ,exitter-password) + ("link" . "next_link"))) + ("subtask_id" . "LoginEnterPassword"))]))) + :type "POST" + :parser 'json-read + :success (cl-function + (lambda (&key data &allow-other-keys) + (print data) + )) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))) + )) + +(defun exitter-enter-email (flow-token headers) (message "entering exitter-enter-email") - (let ((request-curl-options `(,exitter-agent-param))) - (request exitter-url-task - :params '(("lang" . "en")) - :headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token)) - ("Content-type" . "application/json") - ("X-Guest-Token" . ,guest-token) - ("att" . ,att) - ("cookie" . ,(format "att=%s" att))) - :data (json-encode - `(("flow_token" . ,flow-token) - ("subtask_inputs" . - [(("enter_text" . - (("text" . ,exitter-email) - ("link" . "next_link"))) - ("subtask_id" . "LoginEnterAlternateIdentifierSubtask"))]))) - :type "POST" - :parser 'json-read - :success (cl-function - (lambda (&key data &allow-other-keys) - (print data) - )) - :error - (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) - (message "Got error: %S" error-thrown))) - ))) + (request exitter-url-task + :params '(("lang" . "en")) + :headers headers + :data (json-encode + `(("flow_token" . ,flow-token) + ("subtask_inputs" . + [(("enter_text" . + (("text" . ,exitter-email) + ("link" . "next_link"))) + ("subtask_id" . "LoginEnterAlternateIdentifierSubtask"))]))) + :type "POST" + :parser 'json-read + :success (cl-function + (lambda (&key data &allow-other-keys) + (print data) + )) + :error + (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "Got error: %S" error-thrown))) + )) (provide 'exitter) |