[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: http-request bearer token syntax for Twitter v2 api
From: |
Mortimer Cladwell |
Subject: |
Re: http-request bearer token syntax for Twitter v2 api |
Date: |
Thu, 13 Oct 2022 16:42:03 -0400 |
Thanks Ricardo.
I used your over-writes and modified my code below:
(let* (
(uri "https://api.twitter.com/2/tweets")
(data "{\"text\":\"Hello world!\"}")
(access-token "abcde....myaccesstoken")
(my-headers `((Content-type . "application/json")(authorization . (bearer .
,access-token)) ))
)
(call-with-values (lambda () (http-request uri #:method 'POST #:body data
#:headers my-headers))
(lambda (response body)
(pretty-print response)
(pretty-print (json-string->scm (utf8->string body)))))
)
the error body:
(("type"
.
"https://api.twitter.com/2/problems/invalid-request")
("detail"
.
"One or more parameters to your request was invalid.")
("title" . "Invalid Request")
("errors"
.
#((("message"
.
"Requests with bodies must have content-type of
application/json.")))))
>>Note that the POST endpoint for submitting tweets does not allow bearer
token authentication.
I am using Oauth2 with PKCE. I submit an authorization token to obtain and
access-token and refresh token. I can then successfully tweet with the
guile/curl code:
(let* ((access-token "abcde....myaccesstoken")
(a "--header")
(b "Content-type: application/json")
(c (string-append "Authorization: Bearer " access-token))
(d "{\"text\":\"Yay! I’m Tweeting from the API!\"}")
)
(system* "curl" "--cacert" "./ca/cacert.pem" "-X" "POST" "
https://api.twitter.com/2/tweets" a b a c "-d" d)
))
Note I am using an access token with "...Bearer...". A twitter bug? or I am
confused by the terminology. In any case works with curl but not guile
http-request.
Thanks
Mortimer