-2

I know very basic of javascript and this is my second call to Facebook API and I am having a problem. I need to read the list of user's events. Here is my code inside a function:

FB.api('/me/events', function(response) {
        console.log("event id: " + response.data[0].id);  
    });

Output is:

Uncaught TypeError: Cannot read property 'id' of undefined

I tried to outout this:

FB.api('/me/events', function(response) {
        console.log("event id: " + response.data[0]);  
    });

event id: undefined

I have already created couple of events and join couple of events. And also I used this:

FB.api('/me', function(response) {

      var str="<b>Name</b> : "+response.name+"<br>";
          str +="<b>Link: </b>"+response.link+"<br>";

And it works fine. So there shouldn't be a problem with user login. I appreciate if anyone can help me with this.

Bernard
  • 4,240
  • 18
  • 55
  • 88
  • What's in the `response` object? – Tobi Jul 14 '15 at 09:45
  • 1
    Did you ask the user for the permission necessary to access their events? – CBroe Jul 14 '15 at 11:34
  • @Tobi I got this piece of code from here https://developers.facebook.com/docs/graph-api/reference/user/events/ and I need to access these but I dont have event id: https://developers.facebook.com/docs/graph-api/reference/v2.4/event – Bernard Jul 14 '15 at 11:39
  • @Bernard That doesn't answer my question. Do a `console.log(response);` – Tobi Jul 14 '15 at 11:46
  • @CBroe Thanks mate I didn't give permission. If you can write your answer I accept for solution. – Bernard Jul 14 '15 at 11:54

1 Answers1

0

You need to ask the user for user_events permission, before you can access their events.

CBroe
  • 91,630
  • 14
  • 92
  • 150