从emacs查询freebase api

时间:2013-07-01 13:57:02

标签: curl emacs freebase

我有以下Emacs Lisp,它构建了对Freebase的查询。如果我将生成的网址复制并粘贴到我的浏览器中命令行curl我会得到我期望的结果:

  

curl -X GET https://www.googleapis.com/freebase/v1/search?query=Oil%20on%20Canvas&filter=(any%20type%3avisual_art%2fvisual_art_medium) ... 此作品

但是我无法在Emacs中使用它:

(require 'url)
(defvar fb-url "https://www.googleapis.com/freebase/v1/search")

(defvar materials-type "(any type:visual_art/visual_art_medium)")

(defun fbquery (type str)
  (let ((url-request-method "GET")


        (url-request-data (concat "?query=" (url-hexify-string str)
                                  "&filter=" (url-hexify-string type))))
    (url-retrieve (concat fb-url)
                  (lambda (status) (switch-to-buffer (current-buffer))))))

(setq url-debug t)

(fbquery materials-type "Oil on Canvas")

我回来了:

HTTP/1.0 400 Bad Request ... Your client has issued a malformed or illegal request. That's all we know.

你能帮忙吗?

1 个答案:

答案 0 :(得分:1)

似乎问题与变量url-request-data

的解释有关

以下代码适用于我

(defun fbquery (type str)
  (let ((url-request-method "GET")
        (foo (concat "?query=" (url-hexify-string str)
                     "&filter=" (url-hexify-string type))))
    (url-retrieve (concat fb-url foo)
                  (lambda (status) (switch-to-buffer (current-buffer))))))

请注意,我重命名了该变量(以避免错误)并将其连接到url