From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mortimer Cladwell Newsgroups: gmane.lisp.guile.user Subject: Re: http-request bearer token syntax for Twitter v2 api Date: Thu, 13 Oct 2022 16:42:03 -0400 Message-ID: References: <87h708gdfg.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15168"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Ricardo Wurmus Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Oct 13 22:42:45 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 1oj52T-0003pR-KM for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 22:42:45 +0200 Original-Received: from localhost ([::1]:46446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oj52S-00081N-Ko for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 16:42:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oj525-0007x4-Sz for guile-user@gnu.org; Thu, 13 Oct 2022 16:42:21 -0400 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:52871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oj523-0003lO-Sa for guile-user@gnu.org; Thu, 13 Oct 2022 16:42:21 -0400 Original-Received: by mail-pj1-x102f.google.com with SMTP id pq16so3058534pjb.2 for ; Thu, 13 Oct 2022 13:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5PPF+q2W2XI469Joz243eHnz1F/7g5DHSVBPoztQCyg=; b=a9SwV4gIFfXXE4E4Pxe78OsWVqpKqVZ+KCgNFiI4EAvZ2rhlmKRAYrm/oK4REP8Jv0 yj5x8f21YNmV+BCVQswjwMVipFHvVW3P8AgZx1UZt81kWIi0vO4qIw99iKUHIDCOhgyn M/fcgQTIAlhsqeOMqaUrGOCFjFct+FQQBNMRzQ3e8nDORolumnvx3DUkgbbyxRn6fuIt jGS/O2yNFamaxE50Ys82Ew3ATMbsuB/O0LKIEV1MyP52Jop7KBvIpZMbyWs+cJpzblfa GpxKV/i9ilKQf4P4mybNMoRWl8kcUZE5lK0blig/K+CNzfjmD48bYrzeD7INtBBiWzoN BEGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5PPF+q2W2XI469Joz243eHnz1F/7g5DHSVBPoztQCyg=; b=R5yNvzILbGSrjBcZ/Qyr7xnqr3k+aLg1QjpJYZsCbS3dIDyl43CWayMF4kAgDzZvL6 A4MhvtBZaS5Z813ZyYTbKvucnO6OLDdJsMgIlufCAlYSftmO8SwWLFFtnndQChz+IULc 1SZagkjt8k3oHVjU+j3ecFFF9JptQ2mG3vEmTo+o0bpnUbu9jbKLicph/GEHHa9RudD1 Ap4G7b60GllpZzc8ib+BfJRjzmeDlxm4Smlt6NKOp2GmyMLAb6Nb2IIrhHwW8i7j1rne Zg55taJEaPPBZLZw6fbQWuCo0Rt4TF98mD0td/7gFkrJ9aW/dxpQudhQWW7iIIOfBVp/ TAxw== X-Gm-Message-State: ACrzQf0BCirCAc7zqcqlcFVOTzPtKUa5DihEoInMtev4iXsUllB9zbCQ QP7T/2kmZrHAcRdPXKkO7Js0MvkNURSS63563aE= X-Google-Smtp-Source: AMsMyM6ZVh29gv786czK3c0u6sn2be46R9FKLJCj+lPP4C2jtIrShnWMeaKYEDhSJDVMQZHoRZAUkmuz0aSHwaU+lRA= X-Received: by 2002:a17:902:ce03:b0:178:3ba6:f731 with SMTP id k3-20020a170902ce0300b001783ba6f731mr1798910plg.115.1665693735471; Thu, 13 Oct 2022 13:42:15 -0700 (PDT) In-Reply-To: <87h708gdfg.fsf@elephly.net> Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=mbcladwell@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:18646 Archived-At: 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=E2=80=99m 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