使用 paypal api 的无效客户端,使用 HTTPoison.post!/3 的客户端身份验证失败
Invalid Client with paypal api, client authentication failed using HTTPoison.post!/3
我正在使用 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 post 请求:
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)
这显示 status_code: 401
和 {\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}",
错误。这个问题如何解决?
HTTP 基本身份验证要求对值进行 base-64 编码。尝试这样做:
Authorization: "Basic " <> Base.encode64("#{ClientID}:#{Secret}")
我正在使用 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 post 请求:
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)
这显示 status_code: 401
和 {\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}",
错误。这个问题如何解决?
HTTP 基本身份验证要求对值进行 base-64 编码。尝试这样做:
Authorization: "Basic " <> Base.encode64("#{ClientID}:#{Secret}")