我正在使用ruby,并使用了一个名为 food2fork.com 的API。
我有两个文件
recipes_controller.rb
和recipes.rb
#recipes.rb
require 'httparty'
class Recipe
include HTTParty
default_options.update(verify: false)
base_uri "http://food2fork.com/api"
default_params key: ENV["FOOD2FORK_KEY"]
format :json
def self.for (para)
get("/search",query: {q:para})["recipes"]
end
end
和第二个文件recipes_controller.rb
require_relative 'recipes'
puts Recipe.for("chocolate")
但是当我在命令行中运行recipes_controller.rb
文件时,出现错误
`
C:\Users\Hamza\module-3-assignment-1>ruby recipes_controller.rb
C:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/json/common.rb:156:in `parse':
822: unexpected token at 'FORBIDDEN' (JSON::ParserError)
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/json/common.rb:156:in `
parse'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/parser.rb:125:in `json'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/parser.rb:145:in `parse_supported_format'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/parser.rb:110:in `parse'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/parser.rb:69:in `call'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/request.rb:391:in `parse_response'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/request.rb:359:in `block in handle_response'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/response.rb:25:in `parsed_response'
from C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/httparty-
0.16.2/lib/httparty/response.rb:96:in `method_missing'
from C:/Users/Hamza/module-3-assignment-1/receipes.rb:12:in `for'
from recipes_controller.rb:4:in `<main>'
答案 0 :(得分:0)
您似乎发送了错误的api密钥
尝试这样做:
qp.And(cbft.NewConjunctionQuery( cbft.NewMatchQuery("Available").Field("status") ))