【问题标题】:Coinbase API invalid request (oauth token)Coinbase API 无效请求(oauth 令牌)
【发布时间】:2019-10-02 00:17:35
【问题描述】:

我正在尝试使用 Coinbase API for 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. 未能成功交换访问令牌的代码 发布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

【问题讨论】:

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


    【解决方案1】:

    我不需要为所有参数使用setValue,而是将它们发布为request.httpBody

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 2014-08-29
      • 2013-11-16
      • 2012-05-01
      相关资源
      最近更新 更多