首页 > 解决方案 > Facebook Graph Places Search API 不工作

问题描述

我想使用 Facebook Graph Places Search API 来提取地点的图片,但是我收到错误 0f 400 bad request。我尝试使用用户访问令牌和应用程序令牌,但它仍然不起作用

这是代码

let input = document.getElementById("input");

document.getElementById("btn").addEventListener("click", () => {

let xhr = new XMLHttpRequest();

xhr.open("GET","https://graph.facebook.com/search?type=place&q=" + input.value + "&fields=picture&limit=3&access_token=XXXXXXXXXXXXXXXXXXXXXXX")

xhr.onload = function () {
    if (this.status === 200) {
    let data = JSON.parse(responseText)
    console.log(data);      
    }
}

xhr.send();

})

标签: javascriptajaxfacebook-graph-apixmlhttprequest

解决方案


根据您使用的 API 版本,这很可能是由于图片字段,您应该会看到类似的错误响应(#100) Tried accessing nonexisting field (picture) on node type (PlaceInformation),从请求中删除图片字段或为该请求指定 API 版本(最大为 v3.2)。


推荐阅读