2015-09-21 34 views
1

我試圖在withings API(withings-simplificator gem)中設置通知。我總是得到這個錯誤,無論輸入怎樣的URL,或者如果我編碼與否:Withings API:回調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:

於是,我就沒有simplificator寶石withings:

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

回調URL是否需要解析?如果是這樣,它可能需要一個可以通過DNS解析的有效主機名。 – tadman

+0

我應該補充說,所有其他的API調用都是成功的,@tadman,我也用一個「真正的」URL進行了測試,解決了這個問題。 (我可以從中獲取並用我的瀏覽器推送它。)仍然是相同的錯誤... – jlxq0

+0

@ jlxq0你找到了這個答案嗎?我窒息了它 –

回答

0

你必須在安裝過程中,以確保

  • 你的「觸發網址」存在
  • 它用「OK」來響應POST
  • 速度快...我想不出這確切地說有多快,但我認爲響應時間應該是< 1秒

有了這樣的環境,我的代碼如上所述。