【问题标题】:Withings API: The callback URL is either unknown or invalidWithings API:回调 URL 未知或无效
【发布时间】:2015-09-21 22:02:43
【问题描述】:

我正在尝试在 withings API 中设置通知(使用 withings-simplificator gem)。无论我输入什么 URL 或是否对其进行编码,我总是会收到此错误:

irb(main):013:0> user.subscribe_notification('http://foo.bar.com', 'test subscription')
Withings::ApiError: The callback URL 'http://foo.bar.com' is either unknown or invalid - Status code: 293
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:80:in `verify_response!'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:22:in `get_request'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:27:in `get_request'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/user.rb:26:in `subscribe_notification'
  from (irb):13
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
  from bin/rails:8:in `require'
  from bin/rails:8:in `<main>'

有没有人遇到过这个问题并有解决办法?

更新 1:

所以我尝试不使用 withings 简化器 gem:

API_KEY       = '123'
API_SECRET    = '456'
USER_ID       = '789'
USER_KEY      = 'abc'
USER_SECRET   = 'def'
CONFIGURATION = {               site: 'https://oauth.withings.com',
                  request_token_path: '/account/request_token',
                   access_token_path: '/account/access_token',
                      authorize_path: '/account/authorize',
                         http_method: :get,
                              scheme: :query_string
                }

@consumer = OAuth::Consumer.new API_KEY, API_SECRET, CONFIGURATION

@access_token = OAuth::AccessToken.new @consumer, USER_KEY, USER_SECRET

url = ERB::Util.url_encode("www.foo.bar/trigger")
comment = ERB::Util.url_encode("Trigger")
response = @access_token.get("https://wbsapi.withings.net/notify?action=subscribe&userid=#{USER_ID}&callbackurl=#{url}&comment=#{comment}")
JSON.parse(response.body)

同样的错误:

irb(main):051:0>   JSON.parse(response.body)
=> {"status"=>293}

我做错了什么?

【问题讨论】:

  • 回调URL需要解析吗?如果是这样,它可能需要一个可以用 DNS 解析的有效主机名。
  • 我应该补充一点,所有其他 API 调用都是成功的,@tadman,我还使用“真实”URL 进行了测试,它可以解决。 (我可以从中获取并使用浏览器推送到它。)仍然是同样的错误......
  • @jlxq0 你找到答案了吗?我被它困住了

标签: ruby-on-rails ruby withings


【解决方案1】:

您必须在设置过程中确保

  • 您的“触发网址”存在
  • 它以“ok”响应 POST
  • 它很快...我无法确定到底有多快,但我认为响应时间应该是

有了这样的环境,我上面的代码就可以工作了。

【讨论】:

    【解决方案2】:

    您的通知端点将执行两项操作:

    1. 它将响应测试请求响应(当您注册时,它将检查您的 URL 是否存在)。您将收到带有空正文对象的电话。如果没有userid,则不是数据通知,因此必须以空体响应状态为200;
    2. 成功注册后,您将收到数据警报。这一次你可以通过你的业务逻辑来处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 2023-03-18
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      相关资源
      最近更新 更多