From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: James Crake-Merani Newsgroups: gmane.lisp.guile.user Subject: Re: http-request bearer token syntax for Twitter v2 api Date: Thu, 13 Oct 2022 06:53:11 +0100 Message-ID: <20221013055311.v2nl5vmzatrs5xts@jamescrake-meraniarch> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8033"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Mortimer Cladwell Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Oct 13 08:03:10 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oirJF-0001ok-AA for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 08:03:09 +0200 Original-Received: from localhost ([::1]:45968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oirJB-0004db-Ra for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 02:03:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oirHx-0004d6-Vd for guile-user@gnu.org; Thu, 13 Oct 2022 02:01:50 -0400 Original-Received: from [178.62.35.155] (port=46854 helo=jamescm.co.uk) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oirHw-0007tl-1B for guile-user@gnu.org; Thu, 13 Oct 2022 02:01:49 -0400 Original-Received: from localhost (unknown [131.251.33.92]) by jamescm.co.uk (Postfix) with ESMTPSA id 08AFF60DDF; Thu, 13 Oct 2022 05:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=jamescm.co.uk; s=mail; t=1665640392; bh=0iHdo/KVq9ewEkTL7108DDQu3njAd6brvSb6ZK8hynU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HYNnBZ3IjlH/NwtP5IQCeLe53WFcyPw66e0x5b6r4U6+7WDtGZ4XxSo7zfCHnzGuh VWpN3F2CzD6IhK2T29YjuuSxkHa8nqioztXkQLleThy6RpFLEd+bMBLxQXXSTYyqon YLbIP4eCqhVEqRMrob9KfyL2zJluC+UtK6h4hKasgLBZsHoPRx2FcYUn0bNSxApb+1 5hgZhQQir+tKB093keHI2AwgPMLHdA2KE6nBvpBK4c0L+zvnRxggWKdfb6YZu0WBe/ ccfYQ42v3I1TUlgjK3DA0tJYFnRYwUlxN9koNwpcPDUPtHI6XCxursgenlpRgottYn D/pkquyIexF9w== Content-Disposition: inline In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 178.62.35.155 (failed) Received-SPF: pass client-ip=178.62.35.155; envelope-from=james@jamescm.co.uk; helo=jamescm.co.uk X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18631 Archived-At: 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.