Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PayPal OAuth:400错误,即使在指定主机后也是如此_Paypal_Go_Paypal Sandbox - Fatal编程技术网

PayPal OAuth:400错误,即使在指定主机后也是如此

PayPal OAuth:400错误,即使在指定主机后也是如此,paypal,go,paypal-sandbox,Paypal,Go,Paypal Sandbox,我在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-La

我在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", "close")
我已经设置了auth,还有我想添加的每个标题。我仔细阅读了文档,并尝试了poke-it,看看它是否也能正常工作。这是我在邮件请求中传递的信息

`{"grant_type": "client_credentials"}`

 42     req, err := http.NewRequest(
 43         "POST", 
 44         app.Endpoint + oauthEndpoint,
 45         strings.NewReader(`{"grant_type": "client_credentials"}`),
 46     )
如果你需要更多的代码,请告诉我。但我不确定这会有多好。我想让这个职位尽可能的通用

编辑:

因此,尽管我正在手动指定有效负载中的grant_类型,但它似乎失败了,因为
grant_类型
未被识别

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


Header.Set()
不会添加新的头。您需要
标题。添加()
。请参阅上面的文档链接

问题是我的读者对象,应该是

strings.NewReader("grant_type=client_identifier")

当我使用Add时,它的工作原理就不一样了。当我使用Set时,头映射中也显示了头,我在调试过程中验证了这一点