“未捕获(承诺)未定义"在 Facebook Graph API 查询中使用 with=location 时出错 [英] "Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query

查看:11
本文介绍了“未捕获(承诺)未定义"在 Facebook Graph API 查询中使用 with=location 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Facebook Graph API 开发 Web 应用程序.

我目前的目标是只检索附加了位置的帖子.

虽然检索带位置和不带位置的帖子已经有效,但我无法仅检索带位置的帖子.

检索这两种类型的查询如下所示:'/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location'

应该只检索带有位置的帖子的查询如下所示:/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location

我遇到的问题是,使用参数 &with=location 我在代码的这一部分收到错误 Uncaught (in promise) undefined:>

if (response.paging && response.paging.next) {recursiveAPICall(response.paging.next);} 别的 {解决(postsArr);}} 别的 {//错误信息来自这里拒绝();}

日志显示如下:

调试: -------------------------------调试:灰烬:2.4.5调试:Ember 数据:2.5.3调试:jQuery:2.2.4调试:Ember 简单身份验证:1.1.0调试: -------------------------------对象 {错误:对象}错误:目标代码:代码:11fbtrace_id:H5cXMe7TJIn"消息:发生未知错误."类型:OAuthException"__proto__:对象__proto__:对象Uncaught (in promise) undefined

有没有人对此有可能的解决方案?

有关代码的详细信息,请参阅我的 上一个问题.

解决方案

错误告诉您存在错误,但您没有发现.这是您可以捕获它的方法:

getAllPosts().then(response => {控制台日志(响应);}).catch(e => {控制台日志(e);});

你也可以在你的API回调函数的开头放一个console.log(reponse),里面肯定有Graph API的错误信息.

更多信息:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch

或者使用异步/等待:

//一些异步函数尝试 {让响应 = 等待 getAllPosts();}赶上(e){控制台日志(e);}

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 retrieving posts with and without location is already working, I am not able to retrieve only posts with location.

The query which retrieves both types looks like this: '/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location'

The query which should retrieve only posts with location looks like this: /me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location

The problem I have is that with the parameter &with=location I get an error Uncaught (in promise) undefined at this part of my code:

if (response.paging && response.paging.next) {
    recursiveAPICall(response.paging.next);
  } else {
    resolve(postsArr);
  }
} else {
  // Error message comes from here
  reject();
}

Log shows the following:

DEBUG: -------------------------------
DEBUG: Ember             : 2.4.5
DEBUG: Ember Data        : 2.5.3
DEBUG: jQuery            : 2.2.4
DEBUG: Ember Simple Auth : 1.1.0
DEBUG: -------------------------------
Object {error: Object}
  error: Objectcode: 
    code: 1
    1fbtrace_id: "H5cXMe7TJIn"
    message: "An unknown error has occurred."
    type: "OAuthException"
    __proto__: Object
  __proto__: Object
Uncaught (in promise) undefined

Does anyone have a possible solution for this?

For further information how the code looks like see my previous question.

解决方案

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);
}

这篇关于“未捕获(承诺)未定义"在 Facebook Graph API 查询中使用 with=location 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆