From: Mortimer Cladwell <mbcladwell@gmail.com>
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guile-user@gnu.org
Subject: Re: http-request bearer token syntax for Twitter v2 api
Date: Thu, 13 Oct 2022 16:42:03 -0400 [thread overview]
Message-ID: <CAOcxjM4eOdkYsanPFm5k_D1ichr1E5yWBVpO=kdk_XZetR4tEA@mail.gmail.com> (raw)
In-Reply-To: <87h708gdfg.fsf@elephly.net>
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
prev parent reply other threads:[~2022-10-13 20:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 10:30 http-request bearer token syntax for Twitter v2 api Mortimer Cladwell
2022-10-12 11:06 ` Olivier Dion via General Guile related discussions
2022-10-12 18:33 ` Mortimer Cladwell
2022-10-13 5:53 ` James Crake-Merani
2022-10-13 8:53 ` Maxime Devos
2022-10-13 11:37 ` Ricardo Wurmus
2022-10-13 20:42 ` Mortimer Cladwell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOcxjM4eOdkYsanPFm5k_D1ichr1E5yWBVpO=kdk_XZetR4tEA@mail.gmail.com' \
--to=mbcladwell@gmail.com \
--cc=guile-user@gnu.org \
--cc=rekado@elephly.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).