javascriptfacebookfacebook-eventsfacebook-graph-api-v2.3

How to access events created by user in Facebook API by using Javascript?


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.


Solution

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