Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting the cited-id from a newly posted tweet? #147

Open
jkitchin opened this issue Mar 25, 2018 · 1 comment
Open

getting the cited-id from a newly posted tweet? #147

jkitchin opened this issue Mar 25, 2018 · 1 comment

Comments

@jkitchin
Copy link

If I use code like this:

(twittering-call-api 'update-status '((status . "you got it 5")))

I can post tweets. I wonder how I can get the cited-id for that tweet though, so I can reply to it in a thread. Any hints?

@ketan0
Copy link

ketan0 commented Nov 21, 2020

For anyone who's interested, this is possible! just needs a little bit of a workaround, because while twittering-call-api allows for 'sentinel' functions (i.e. callbacks called upon completion of the request) passed through the args-alist parameter, curiously for many of the API endpoints, update-status included, the sentinel is ignored. 🤔

Using update-status as an example, you can tweak twittering-mode.el as follows to extract and pass on the sentinel (line 6805):

Before:

 ((eq command 'update-status)
    ;; Post a tweet.
    (let* ((status (cdr (assq 'status args-alist)))
	   (id (cdr (assq 'in-reply-to-status-id args-alist)))
	   (host twittering-api-host)
	   (method "1.1/statuses/update")
	   (http-parameters
	    `(("status" . ,status)
	      ,@(when id `(("in_reply_to_status_id" . ,id)))))
	   (format-str "json"))
      (twittering-http-post account-info-alist host method http-parameters
			    format-str additional-info)))

After:

 ((eq command 'update-status)
    ;; Post a tweet.
    (let* ((status (cdr (assq 'status args-alist)))
	   (sentinel (cdr (assq 'sentinel args-alist))) ;; added this line
	   (id (cdr (assq 'in-reply-to-status-id args-alist)))
	   (host twittering-api-host)
	   (method "1.1/statuses/update")
	   (http-parameters
	    `(("status" . ,status)
	      ,@(when id `(("in_reply_to_status_id" . ,id)))))
	   (format-str "json"))
      (twittering-http-post account-info-alist host method http-parameters
			    format-str additional-info (or sentinel 'ignore)))) ;; changed this line

Then you can pass a sentinel to the request and extract the tweet id as follows:

(defun my-sentinel (proc status connection-info header-info)
  (message
   (let ((status-line (cdr (assq 'status-line header-info)))
         (status-code (cdr (assq 'status-code header-info))))
     (case-string
      status-code
      (("200")
       (let ((json-response (twittering-json-read)))
         "the tweet id is: %s" (alist-get 'id json-response)))
      (t
       (format "Response: %s"
               (twittering-get-error-message header-info connection-info)))))))

(twittering-call-api 'update-status '((status . "hello twitter")
                                      (sentinel . my-sentinel)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants