The method FB.api()
lets you make calls to the Graph API.
FB.api(path, method, params, callback)
Name | Type | Description |
---|---|---|
|
| This is the Graph API endpoint path that you want to call. You can read the Graph API reference docs to see which endpoint you want to use. This is a required parameter. |
|
| This is the HTTP method that you want to use for the API request. Consult the Graph API reference docs to see which method you need to use. Default is |
|
| This is an object consisting of any parameters that you want to pass into your Graph API call. The parameters that can be used vary depending on the endpoint being called, so check the Graph API reference docs for full lists of available parameters. One parameter of note is |
|
| This is the function that is triggered whenever the API returns a response. The response object available to this function contains the API result. |
FB.api('/113124472034820', function(response) { console.log(response); });
FB.api('/me', {fields: 'last_name'}, function(response) { console.log(response); });
var body = 'Reading JS SDK documentation'; FB.api('/me/feed', 'post', { message: body }, function(response) { if (!response || response.error) { alert('Error occured'); } else { alert('Post ID: ' + response.id); } });
var postId = '1234567890'; FB.api(postId, 'delete', function(response) { if (!response || response.error) { alert('Error occured'); } else { alert('Post was deleted'); } });
var pageAccessToken = '1234567890|faketoken'; FB.api('/me/conversations', { access_token : pageAccessToken });