Coinbase API无效请求(oauth令牌)

时间:2019-05-14 22:26:30

标签: ios swift oauth oauth-2.0 coinbase-api

我正在尝试使用 Coinbase API进行oauth ,但一直收到无效的请求响应“”该请求缺少必需的参数,包含了不受支持的参数值或格式错误。”

按照他们的指南https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating,我可以:

  1. 成功重定向用户以请求Coinbase访问

获取https://www.coinbase.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URL&state=SECURE_RANDOM&scope=wallet:accounts:read

  1. 成功将Coinbase重定向回您的网站

获取https://example.com/oauth/callback?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8&state=134ef5504a94 app:// oauth-coins?code = 4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8

  1. 未成功交换访问令牌的代码 POST https://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的所有参数,而是将其发布为request.httpBody

1 个答案:

答案 0 :(得分:0)

我不需要setValue的所有参数,而是将其发布为request.httpBody