使用 Ruby XMLRPC 使用开发人员密钥进行 UPC 数据库查找
这段代码有什么问题?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这太有趣了,我只是在同一件事上撞我的头。此代码对我有用:
编辑:我还发现 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:
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.