How-To: Use the Graph API to Manage Events

The Graph API already supported creating and deleting events. Now, you can also manage invite lists and check RSVP status for events using the Graph API. All of these new features work from the /EVENT_ID connection, following standard Graph API conventions. The following are the newly introduced APIs for managing events; see the Graph APIEvent object for full details.

Managing Invite Lists

You can issue the following HTTP requests to view or modify the invite list for an event:

GET /EVENT_ID/invited/USER_ID

Check if USER_ID is invited to the event. This returns an object with name, id, and rsvp_status('not_replied', 'unsure', 'attending', or 'declined') fields. Requires user_eventsor friends_events permission for non-public events.

POST /EVENT_ID/invited/USER_ID

Invite a user to an event. Returns true if the request is successful.

POST /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3

Invite multiple users to an event. Returns true if the request is successful.

DELETE /EVENT_ID/invited/uid

Un-Invite a user from an event. Returns true if the request is successful. The user must be an admin of the event for this call to succeed. Requires rsvp_event permission.

Querying RSVP Status

You can issue the following HTTP requests to query the RSVP status of an event:

GET /EVENT_ID/attending/USER_ID

Check if USER_ID is attending the event (i.e. they RSVP’d yes)

GET /EVENT_ID/maybe/USER_ID

Check if USER_ID RSVP’d ‘maybe’ for the event

GET /EVENT_ID/declined/USER_ID

Check if USER_ID RSVP’d declined the event (i.e. they RSVP’s no)

GET /EVENT_ID/noreply/USER_ID

Check if USER_ID has not yet replied to the event invite

The above methods return an object with name, id, and rsvp_status ('not_replied', 'unsure', 'attending', or 'declined'). If the user is not invited to the event, the API will return an empty data array.

How To @ Tag An User While Publishing A Post Via Facebook Graph API

here is the example php code

$uid = ”1234567890″; //User’s Facebook ID, set the value as “me” if publishing on logged in user’s wall
$ufname = ”Nikka Mormola”; // User’s Full name on Facebook
$attachment = array(
‘message’=> ”Happy Birthday, @[".$uid.":1:".$ufname."]!”,
);
try {
$post = $facebook->api(‘/’.$uid.’/feed’, ’post’, $attachment);
print_r($pp); //show the tagged post ID
} catch (FacebookApiException $e) {
//Error
exit;
}

Using FB.api to make a full post to a users wall

I just thought I’d make another quick post about the Facebook Graph API seen as there seems to be so little documentation and examples for it. The below example shows you how to make a full wall post with message, name, description, link, picture and caption to the wall of a Facebook user using JavaScript to call the Facebook FB.api.

So, assuming that you have an authenticated session, here’s what you need to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var params = {};
params['message'] = 'Message';
params['name'] = 'Name';
params['description'] = 'Description';
params['caption'] = 'Caption';
 
FB.api('/me/feed', 'post', params, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Published to stream - you might want to delete it now!');
  }
});

Create photo albums and upload photos using the Facebook Graph API

I thought I’d share some recent learning’s with using the Facebook Graph API as there seems to be so few examples out there about how to utilise various aspects of its functionality. I will explain how to create a photo album and then insert a photo into it using PHP.

The code example assumes that you have already generated an authenticated session and have the correct permissions (read_stream, publish_stream, photo_upload, user_photos, user_photo_video_tags). If you haven’t already done so, then there is a good example here about how to do so and you can read more about the Facebook permissions on theFacebook dev site.

The following snippet creates a photo album and then uploads a photo into it:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);
 
//Create an album
$album_details = array(
        'message'=> 'Album desc',
        'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
 
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
 
//Upload a photo to album of ID...
$photo_details = array(
    'message'=> 'Photo message'
);
$file='app.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file);
 
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

Facebook Open Graph META Tags Example

<meta property="og:title" content=""/>
<meta property="og:image" content="http://davidwalsh.name/wp-content/themes/klass/img/facebooklogo.png"/>
<meta property="og:site_name" content="David Walsh Blog"/>
<meta property="og:description" content="Facebook's Open Graph protocol allows for web developers to turn their websites into Facebook "graph" objects, allowing a certain level of customization over how information is carried over from a non-Facebook website to Facebook when a page is 'recommended', 'liked', or just generally shared."/>

Building an app on Facebook

Building an app on Facebook gives you the opportunity to deeply integrate into the core Facebook experience. Your application can integrate with many aspects of Facebook.com, including the News Feed and Notifications. All of the core Facebook Platform technologies, such as Social Plugins, the Graph API and Platform Dialogs are available to Applications on Facebook. Continue reading