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.