使用 Ruby XMLRPC 使用开发人员密钥进行 UPC 数据库查找

发布于 2024-12-16 15:52:34 字数 751 浏览 1 评论 0原文

这段代码有什么问题?

require 'xmlrpc/client'
def find_product(key, upc)
  server = XMLRPC::Client.new2('http://www.upcdatabase.com/xmlrpc')
  begin
    response = server.call('lookup',[{'rpc_key' => key}, {'upc' =>upc}] )
    rescue XMLRPC::FaultException => e
    puts "Error: "
    puts e.faultCode
    puts e.faultString
  end
end
dev_key  = '40bf22cb32833a2af48fd65121128fc28e42d580'
upc_code = '099482409463'
puts find_product(dev_key, upc_code)

来自UPCdatabase的响应

{"status"=>"fail", "message"=>"Invalid parameters"}

我无法找出哪个参数无效,因为http://www.upcdatabase.com/ 了解他们的 API。

谁能帮助我吗?我使用的是 Ruby 1.9.2

What's wrong with this code?

require 'xmlrpc/client'
def find_product(key, upc)
  server = XMLRPC::Client.new2('http://www.upcdatabase.com/xmlrpc')
  begin
    response = server.call('lookup',[{'rpc_key' => key}, {'upc' =>upc}] )
    rescue XMLRPC::FaultException => e
    puts "Error: "
    puts e.faultCode
    puts e.faultString
  end
end
dev_key  = '40bf22cb32833a2af48fd65121128fc28e42d580'
upc_code = '099482409463'
puts find_product(dev_key, upc_code)

Response from UPCdatabase

{"status"=>"fail", "message"=>"Invalid parameters"}

I am not able to find out, which parameter is invalid, as there is not much information available on http://www.upcdatabase.com/ about their API.

Can anyone help me? I am using Ruby 1.9.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霞映澄塘 2024-12-23 15:52:34

这太有趣了,我只是在同一件事上撞我的头。此代码对我有用:

require 'xmlrpc/client'
server = XMLRPC::Client.new("www.upcdatabase.com", "/xmlrpc")
result = server.call("lookup", 'rpc_key' => "mykey", 'upc' => "071160055506")

编辑:我还发现 http://www.upcdatabase.org/api.php< /a> 实际上有一个 json api,我也会尝试一下,如果你愿意的话,我会发回来。

That is so funny that I was just banging my head on the same thing. This code works for me:

require 'xmlrpc/client'
server = XMLRPC::Client.new("www.upcdatabase.com", "/xmlrpc")
result = server.call("lookup", 'rpc_key' => "mykey", 'upc' => "071160055506")

Edit: I also found http://www.upcdatabase.org/api.php which has actually a json api, I will give that a try also and post back if you would like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文