Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

javascript - "Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...