unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: James Crake-Merani <james@jamescm.co.uk>
To: Mortimer Cladwell <mbcladwell@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: http-request bearer token syntax for Twitter v2 api
Date: Thu, 13 Oct 2022 06:53:11 +0100	[thread overview]
Message-ID: <20221013055311.v2nl5vmzatrs5xts@jamescrake-meraniarch> (raw)
In-Reply-To: <CAOcxjM5QguZtLEEZyF0j7QH7031gJ6bU2cxhPWSq7g+gz3_fHA@mail.gmail.com>

On 22/10/12 06:30am, Mortimer Cladwell wrote:
> Hi,
> Has anyone successfully submitted a bearer token to Twitter v2 api using
> http-request? What syntax did you use? Without success I have tried many
> permutations/splellings/capitalizations of:
> 
>   (let* (
> (uri  "https://api.twitter.com/2/tweets")
> (data "{\"text\":\"Hello world!\"}")
> (my-token (string-append "bearer " "abcde....myaccesstoken"))
> (my-headers `((Content-type . "application/json")(Authorization .
> ,my-token))  )
> )
>       (receive (response body)
>          (http-request uri #:method 'POST #:body data #:headers my-headers)
> (pretty-print response) (pretty-print (utf8->string body))))
> 
> the error body:
> 
> "{\"errors\":[{\"message\":\"Requests with bodies must have content-type of
> application/json.\"}],\"title\":\"Invalid Request\",\"detail\":\"One or
> more parameters to your request was invalid.\",\"type\":\"
> https://api.twitter.com/2/problems/invalid-request\"}"
> 
> I am not sure the "Requests with bodies must have content-type of
> application/json." is the real error. I think it is "Authorization: bearer
> abcde....".  Can http-request handle a bearer token?
> 
> I know my tokens are valid because I can successfully submit them using
> curl.
> Thanks
> Mortimer

Hello,

I'm not sure about the Twitter API but I've had problems using other APIs with the web module. I normally get 400 errors from the API's load balancer, or Cloudflare with no further information about what the error actually is. Under these conditions, I found it near impossible to work out what was causing the problem without trail, and error which wasn't getting me anyway. Eventually, and after much frustration, I started using the guile Curl bindings, and eventually managed to get it to work. I think Curl must be doing something behind the scenes that satisfies these APIs that the web module's http-request doesn't do.

I would much rather use Guile's built-in libraries because they are much more functional whereas Curl uses lots of procedures with side-effects to configure its requests but I just could not get it to work. APIs seem to work in mysterious ways.

Hope that was helpful,
James Crake-Merani.



  parent reply	other threads:[~2022-10-13  5:53 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 [this message]
2022-10-13  8:53 ` Maxime Devos
2022-10-13 11:37 ` Ricardo Wurmus
2022-10-13 20:42   ` Mortimer Cladwell

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=20221013055311.v2nl5vmzatrs5xts@jamescrake-meraniarch \
    --to=james@jamescm.co.uk \
    --cc=guile-user@gnu.org \
    --cc=mbcladwell@gmail.com \
    /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).