“Uncaught (in promise) undefined” error when using with=location in Facebook Graph API query

前端 未结 2 1689
你的背包
你的背包 2020-12-15 15:58

I am currently developing a web application with the Facebook Graph API.

My current goal is to retrieve only posts which have a location attached.

While retr

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 16:15

    The error tells you that there is an error but you don´t catch it. This is how you can catch it:

    getAllPosts().then(response => {
        console.log(response);
    }).catch(e => {
        console.log(e);
    });
    

    You can also just put a console.log(reponse) at the beginning of your API callback function, there is definitely an error message from the Graph API in it.

    More information: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch

    Or with async/await:

    //some async function
    try {
        let response = await getAllPosts();
    } catch(e) {
        console.log(e);
    }
    

提交回复
热议问题