Topic-icon Get attending facebook events of user

Active Subscriptions:

None
9 years 10 months ago #44898 by Geppie030
Hi Support,

i want to get the attending facebook events of the user that is using facebook login.
I found where i can put events in the dropdown for custom db

profile-> facebook.php i added inside $this->providerFields = array(

'events' => 'Events',

and on line 93 i added:

else if ($field == "events")
$perms[] = "user_events";

But it's not working :)
Can you give me a push in the right direction?
Cheers
The topic has been locked.
Support Specialist
9 years 10 months ago #44927 by alzander
Getting the user's events isn't as easy as you want it to be. It's not a standard profile field. It's a whole separate data structure that's returned from the /me/events endpoint of Facebook:
developers.facebook.com/docs/graph-api/r...nce/v2.0/user/events

That will return a list of IDs of Facebook events, which can then be parsed out for title and other information.

For the permission, you're correct that you need the user_events permission. I'd recommend simply setting that in the Configuration -> Facebook -> Additional Permissions area though instead of fuddling with our profile.php file.

Once that's done, you can use code like:
$events = JFBCFactory::provider('facebook')->api('me/events');
That will return the event structures from Facebook. That may be all you need if you just want the ID's. If you need more info about the events, then you'll have to request that data from Facebook as well.

I hope that helps explain a little more. Obviously, if you have a desired function in mind, let me know more details and we may help you determine where best to place the above code.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 10 months ago #44942 by Geppie030
Alex,

So where do i put '$events = JFBCFactory::provider('facebook')->api('me/events');' ? I need to build a new function for that right and put it in
profile-> facebook.php ?

I added 'user_likes,user_activities,user_interests,user_events' to the Additional Permissions area

Getting the id of the events is great but a name would be more powerfull for marketing.
I'm also waiting for permission from facebook but it's not that easy anymore :D
The topic has been locked.
Support Specialist
9 years 10 months ago #44949 by alzander
Yeah, Facebook changed things and now you need to get permission to grab additional information about the user, like events.

As for events, you can add it to the profile or you can put it wherever you want the code to execute. Can you explain a bit more about what you're trying to accomplish, where you want to store the event attendance information and any other info you can provide? If you have a fully custom system that you want to integrate with, it may be best to put the code above in your system. If you're trying to import it automatically into a database, there's a different place to put it. If you simply want it stored as a comma-separated list in a JomSocial field, that's another setup.

There's quite a few ways to do it, and we can gladly give some pointers. Knowing what you want to do and where you want to save the info will help a lot.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 10 months ago #44962 by Geppie030
Sure, what i want to do to put al the names of the attending events in the custom database where i also store the name, email etc. (this is already working with the customdb settings in the component)

So i made a custom table called events (same where i store name, email etc), made a dropdown with events en selected this in the section customdb.

So i want to store the events name here of the user logging in :)
Any idea how i can manage this?
The topic has been locked.
Active Subscriptions:

None
9 years 10 months ago #45099 by Geppie030
Suggestions are still welcome
The topic has been locked.
Support Specialist
9 years 10 months ago #45255 by alzander
I'm very sorry for the delayed response. We released JFBConnect v6.1 late last week, and that's kept us a little more busy that we expected.

I haven't fully tested what you're looking for, but the below should get you started. All the testing is from the Facebook Graph API explorer:
developers.facebook.com/tools/explorer

Go to that page, and use the Get Access Token button. Make sure the "user_events" permissions is set. Then:
* Update the GET query to: /v2.0/me/events You'll get an output like:
{
  "data": [
    {
      "name": "Test event", 
      "start_time": "2014-07-02", 
      "rsvp_status": "attending", 
      "id": "912486538777545"
    }
  ], 
... <some paging controls here>
There may be multiple events listed. From that, you can get a good amount of information about each event for the user: name, start_time, rsvp_status and the event ID.
* For more details about the event itself, you'd need to update the query to just the event ID, like:
/v2.0/912486538777545
That will give you info back, like:
{
  "is_date_only": true, 
  "name": "Test event", 
  "owner": {
    "id": "1251253607", 
    "name": "Alex Sourcecoast"
  }, 
  "privacy": "SECRET", 
  "start_time": "2014-07-02", 
  "updated_time": "2014-07-02T17:07:33+0000", 
  "id": "912486538777545"
}
The details there are just about the same, though with a few more bits of info like owner.

To do the same requests in JFBConnect, you'd do:
$response = JFBCFactory::provider('facebook')->api('me/events');
if (isset($response['data']) && isset($response['data'][0]))
{
   $events = $response['data'];
   foreach ($events as $event)
   {
       $eventDetails = JFBCFactory::provider('facebook')->api($event['id']);
       $title = $eventDetails['name'];
   }
}
That code is 100% untested. I just wrote it above, but it should work, or get you darn close to working.

I hope that helps, but if you have any questions, just let me know!

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 10 months ago #45450 by Geppie030
Hi Alex,

I can understand that you needed your focus on the new version of JFBConnect. I will update my version soon.
So i want to store the name of the events in the customdb fields.
First i have to add 'events' => 'Events' inside $this->providerFields in the profile/facebook.php do it will be in the dropdown in the component.
Then i added " else if (strpos($field, "events") !== false) $perms[] = "user_events"; " inside the function "public function getPermissionsForFields($fields)"

But i can not find where i put your code:
$response = JFBCFactory::provider('facebook')->api('me/events');

if (isset($response) && isset($response[0]))

{

$events = $response;

foreach ($events as $event)

{

$eventDetails = JFBCFactory::provider('facebook')->api($event);

$title = $eventDetails;

}

}

I'm almost there :)
I also made a attending function for a event. Would be also a nice function for sourcecoast
The topic has been locked.
Support Specialist
9 years 10 months ago #45549 by alzander
You'll want to do something similar to this other post about locations .

Basically, in the profile/facebook.php file, add the events field to the providerFields variable as you mentioned.

Then, in the get function at the bottom of that file, add:
if ($path == 'events')
{
   $events = parent::get('events');
   $titles = array();
   if (count($events) > 0)
   {
     foreach ($events as $event) 
     { 
        $eventDetails = JFBCFactory::provider('facebook')->api($event['id']); 
        $titles[] = $eventDetails['name']; 
      } 
    }
    return implode(', ', $titles);
}
That code is *untested*, but should give a good idea of where to start.

I hope that helps, but let us know how it goes.

Thanks,
Alex
The topic has been locked.