我目前正在使用 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);
} else {
resolve(postsArr);
}
} else {
// Error message comes from here
reject();
}
日志显示以下内容:
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
有人有可能解决这个问题吗?
有关代码的更多信息,请参阅我的上一个问题。
该错误告诉您存在错误,但您没有发现它。这是你可以抓住它的方法:
getAllPosts().then(response => {
console.log(response);
}).catch(e => {
console.log(e);
});
你也可以在API回调函数的开头加上一个
console.log(reponse)
,里面肯定有来自Graph API的错误消息。
更多信息:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
或者使用异步/等待:
//some async function
try {
let response = await getAllPosts();
} catch(e) {
console.log(e);
}
reject
实际上有一个参数:这是代码中发生的导致 Promise 被拒绝的异常。因此,当您调用 reject()
时,异常值为 undefined
,因此您得到的错误中的“未定义”部分。
您没有显示使用承诺的代码,但我认为它是这样的:
var promise = doSth();
promise.then(function() { doSthHere(); });
尝试添加一个空的失败调用,如下所示:
promise.then(function() { doSthHere(); }, function() {});
这将防止出现错误。
但是,我会考虑仅在实际错误的情况下调用
reject
,而且......拥有空的异常处理程序并不是最佳的编程实践。
正确的端点 URL: **“https://**us-central1-alskalk-206421.cloudfunctions.net/gcip-connect”
不正确的端点 URL:
“httpshttps://us-99central1-alskalk-206421.cloudfunctions.net/gcip-connect” “htt://us-central1-alskalk-206421.cloudfunctions.net/gcip-connect” 使用不正确的端点 URL 时会发生此错误。确保 URL 格式正确,以“https://”开头,并且没有任何重复或缺失部分。
enter code here