2013-08-25 13:22
浏览 29

PayPal OAuth:即使指定了主机,也会出现400错误

I'm doing this one in golang, and I've been up just about the entire night trying to get it to work. My latest frustration is that I'm getting a 400 error despite the numerous headers I've dropped into my request.

 29     req.SetBasicAuth(app.id, app.secret)
 30     req.Header.Set("Host", "www.sandbox.paypal.com")
 31     req.Header.Set("Accept", "application/json")
 32     req.Header.Set("Accept-Language", "en_US")
 33     req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
 34     req.Header.Set("Connection", "close")

I have auth set up, and every header I could think to add. I've pored over the documentation and have tried the poke it to see if it works approach as well. Heres the information I've been passing in the body with the post request

`{"grant_type": "client_credentials"}`

 42     req, err := http.NewRequest(
 43         "POST", 
 44         app.Endpoint + oauthEndpoint,
 45         strings.NewReader(`{"grant_type": "client_credentials"}`),
 46     )

If you need some more of the code just tell me. But I'm not super sure it'll be a whole lot of good. I wanted to make the post as general as possible as well.


So it seems that despite the fact I am specifying the grant_type in the payload manually it is failing because grant_type is not being recognized

{"error":"invalid_request","error_description":"grant_type is a required parameter"}

图片转代码服务由CSDN问答提供 功能建议

我正在用golang做这个,我整整晚上都在忙着尝试 上班。 我最近的沮丧之处在于,尽管我已将许多标头放入请求中,但仍遇到400错误。

  29 req.SetBasicAuth(app.id,app.secret  )
 30 req.Header.Set(“ Host”,“ www.sandbox.paypal.com”)
 31 req.Header.Set(“ Accept”,“ application / json”)
 32 req.Header。  Set(“ Accept-Language”,“ en_US”)
 33 req.Header.Set(“ Content-Type”,“ application / x-www-form-urlencoded”)
 34 req.Header.Set(“ Connection  “,”关闭“)

我已经设置了身份验证,并且我可以考虑添加每个标头。 我仔细研究了文档,并尝试戳一下它,看看它是否也可行。 这是我在邮寄请求中一直在正文中传递的信息

 `{“ grant_type”:“ client_credentials”}`
 42请求,错误:=  http.NewRequest(
 43“ POST”,
 44 app.Endpoint + oauthEndpoint,
 45个字符串。NewReader(`{“ grant_type”:“ client_credentials”}`),

如果您需要更多代码,请告诉我。 但我不太确定这会带来很多好处。 我也想使帖子尽可能的笼统。


因此,尽管 事实上,我在有效负载中手动指定了Grant_type,但失败了,因为无法识别 grant_type

  {“ error”:“ invalid_request”,“  error_description“:“ grant_type是必需参数”} 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dta43039 2013-08-26 02:53

    Problem was my reader object, it should have been

    解决 无用
    打赏 举报
  • duandanbeng1829 2013-08-25 14:46


    Header.Set() doesn't add a new header. You want Header.Add(). See the documentation link above.

    解决 无用
    打赏 举报

相关推荐 更多相似问题