0

我正在使用 HTTPoison 向 Paypal api 发送请求。这是使用其 api 登录的贝宝文档:https ://developer.paypal.com/docs/log-in-with-paypal/integrate/

当我获得代码并尝试将其交换为访问令牌时,我收到此错误:"{\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}",

这是 HTTPoison.post!/3 发布请求的方式:

url = "https://api-m.sandbox.paypal.com/v1/oauth2/token"
headers = [
  Authorization: "Basic #{ClientID}:#{Secret}" 
]
body = "grant_type=authorization_code&code=#{code}"

HTTPoison.post!(url, body, headers)

这显示了astatus_code: 401{\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}", 错误..这个问题如何解决?

4

1 回答 1

0

HTTP 基本身份验证要求对值进行 base-64 编码。尝试这样做:

Authorization: "Basic " <> Base.encode64("#{ClientID}:#{Secret}")
于 2021-08-03T07:08:19.453 回答