Coinbase API 无效请求(oauth 令牌)
Coinbase API invalid request (oauth token)
我正在尝试使用 Coinbase API 进行 oauth,但不断收到无效的请求响应 "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."
按照他们的指导 https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating,我能够:
- 成功重定向用户以请求访问 Coinbase
- 成功将 Coinbase 重定向回您的网站
获取https://example.com/oauth/callback?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8&state=134ef5504a94
app://oauth-coins?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8
未能成功交换访问令牌代码
POSThttps://api.coinbase.com/oauth/token
let url = URL(string: "https://api.coinbase.com/oauth/token")! //
var request = URLRequest(url: url)
request.setValue("authorization_code", forHTTPHeaderField: "grant_type")
request.setValue("\(self.code)", forHTTPHeaderField: "code")
request.setValue("clientid1234", forHTTPHeaderField: "client_id")
request.setValue("clientsecret1234", forHTTPHeaderField: "client_secret")
request.setValue("app://oauth-coins", forHTTPHeaderField: "redirect_uri")
因为我在 json
:
中得到一个错误 return
{
error = "invalid_request";
"error_description" = "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.";
}
更新(已解决):
我不需要 setValue
所有参数,而是 post 它们作为 request.httpBody
我不需要 setValue
所有参数,而是 post 它们作为 request.httpBody
我正在尝试使用 Coinbase API 进行 oauth,但不断收到无效的请求响应 "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."
按照他们的指导 https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating,我能够:
- 成功重定向用户以请求访问 Coinbase
- 成功将 Coinbase 重定向回您的网站
获取https://example.com/oauth/callback?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8&state=134ef5504a94 app://oauth-coins?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8
未能成功交换访问令牌代码 POSThttps://api.coinbase.com/oauth/token
let url = URL(string: "https://api.coinbase.com/oauth/token")! // var request = URLRequest(url: url) request.setValue("authorization_code", forHTTPHeaderField: "grant_type") request.setValue("\(self.code)", forHTTPHeaderField: "code") request.setValue("clientid1234", forHTTPHeaderField: "client_id") request.setValue("clientsecret1234", forHTTPHeaderField: "client_secret") request.setValue("app://oauth-coins", forHTTPHeaderField: "redirect_uri")
因为我在 json
:
{
error = "invalid_request";
"error_description" = "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.";
}
更新(已解决):
我不需要 setValue
所有参数,而是 post 它们作为 request.httpBody
我不需要 setValue
所有参数,而是 post 它们作为 request.httpBody