我试图在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的simpleificator 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}
我做错了什么?
答案 0 :(得分:0)
您必须在安装过程中确保
在这样的环境下,我的代码可以正常工作。
答案 1 :(得分:0)
您的通知端点将执行两项操作:
userid
,则它不是数据通知,因此您必须将状态为200的状态为空。