Skip to content

Facebook

Jabran Rafique edited this page Oct 14, 2015 · 12 revisions

HomeAPI ReferenceFacebook

Setup

Facebook SDK can be setup using following method and settings:

/**
 * Setup Facebook SDK
 *
 * @param Object settings
 * @return Object
 */
new Socialmedia.Facebook( settings );

The settings object is made of following parameters:

Required parameter

/**
 * Facebook APP ID
 *
 * @type: String|Numeric String
 * @default: NULL
 * @throws: Error
 */
appid: '0123456789'

Setup Parse

You must provide Parse app ID and Key to enable support for Parse. Create a Parse app at https://www.parse.com/apps and get app ID and Key to use.

/**
 * Parse App ID
 *
 * @type: String
 * @default: NULL
 * @throws: Error if Parse App Key is missing
 */
parseId: 'abc123456789xyz'

/**
 * Parse App Key
 *
 * @type: String
 * @default: NULL
 * @throws: Error if Parse App ID is missing
 */
parseKey: 'abc123456789xyz'

Optional parameters

/**
 * Enable/disable SDK to check
 * user login status itself
 *
 * @type: Boolean
 * @default: false
 */
status: false

/**
 * Enable/disable XFBML
 * XFBML parses & renders Facebook elements in app
 * This option will always be FALSE when using Parse.
 *  
 * @type: Boolean
 * @default: true
 */
xfbml: true

/**
 * Enable/disable cookies for session storage
 *
 * @type: Boolean
 * @default: true
 */
cookie: true

/**
 * Enable/disable Frictionless requests
 *
 * @type: Boolean
 * @default: false
 */
requests: false

/**
 * Load specific Facebook SDK version
 *
 * @type: String
 * @default: Latest
 */
version: 'v2.4'

/**
 * Enable/disable debug mode with uncompressed version
 *
 * @type: Boolean
 * @default: false
 */
debug: false

/**
 * Facebook Canvas autogrow on content update
 * This option will always be FALSE when using Parse.
 *
 * @type: Boolean
 * @default: true
 */
autogrow: true

/**
 * Channel URL for Cross-Origin Resource Sharing (CORS)
 *
 * @type: String
 * @default: NULL
 */
channel: ''

/**
 * Asynchronous callback function
 *
 * Any methods that rely on Facebook SDK must
 * be called using this callback function as it
 * runs asynchronously after Facebook SDKs are loaded.
 *
 * This function runs FB.getLoginStatus in background
 * and returns a Graph API Object with current user status
 *
 * @type: Function
 * @param: Graph API Object response
 * @default: Function
 */
callback: function(response) {}

API

socialmedia exposes following API for Facebook platform:

# facebook.AddFriend({...})

/**
 * Send a Facebook user friend request
 *
 * @param Object options
 * @return Void
 */

facebook.AddFriend(Object options);

The options object accepts following parameters:

/**
 * ID or username of Facebook user
 *
 * @type: String
 * @default: NULL
 */
id: ''

/**
 * Hashtag to include in tweet
 *
 * @type: Function
 * @param: Object Graph API response
 * @default: Function
 * @return: Mix|Object|Boolean
 */
callback: function(response) {}

# facebook.AddToPage()

/**
 * Add current app to a
 * Facebook page as Tab app.
 *
 * @return Void
 */

facebook.AddToPage();

# facebook.Invite({...})

/**
 * Invite friends to the app by using
 * apprequest dialog
 *
 * @param Object options
 * @return Void
 */

facebook.Invite(Object options);

The options object accepts following parameters:

/**
 * Title of invite dialog
 *
 * @type: String
 * @default: NULL
 */
title: ''

/**
 * Message for invite dialog
 *
 * @type: String
 * @default: NULL
 */
message: ''

/**
 * Facebook user IDs to send a request
 *
 * @type: Array
 * @default: NULL
 */
to: []

/**
 * Facebook user IDs to exclude
 * from friend list in invite dialog
 *
 * @type: Array
 * @default: NULL
 */
exclude_ids: []

/**
 * Number of maximum recipients to select
 * from friend list in invite dialog
 *
 * @type: Integer
 * @default: NULL
 */
max_recipients: 0

/**
 * Custom data to send within invite request
 *
 * @type: Object
 * @default: NULL
 */
data: {}

/**
 * Callback function with Graph API
 * response object
 *
 * @type: Function
 * @default: NULL
 * @return: Graph API response Object
 */
callback: function(response) {}

# facebook.Pay({...})

/**
 * Pay with Facebook payment system
 *
 * @param Object options
 * @return Void
 */

facebook.Pay(Object options);

The options object accepts following parameters:

/**
 * Absolute URL of a product
 *
 * @type: String
 * @default: NULL
 */
product: ''

/**
 * Callback function with Graph API
 * response object
 *
 * @type: Function
 * @default: NULL
 * @return: Graph API response Object
 */
callback: function(response) {}

# facebook.Send({...})

/**
 * Send a link to Facebook friends
 *
 * @param Object options
 * @return Void
 */

facebook.Send(Object options);

The options object accepts following parameters:

/**
 * Absolute URL to share
 *
 * @type: String
 * @default: NULL
 */
link: ''

# facebook.Share({...})

/**
 * Share a link to Facebook timeline
 *
 * @since Facebook SDK v2.0
 * @param Object options
 * @return Void
 */

facebook.Share(Object options);

The options object accepts following parameters:

/**
 * Absolute URL to share
 *
 * @type: String
 * @default: NULL
 */
href: ''

/**
 * Callback function with
 * Graph API response object
 *
 * @type: Function
 * @default: NULL
 * @return: Graph API response Object
 */
callback: function(response) {}

# facebook.ShareOpenGraph({...})

/**
 * Share a Graph API Object to Facebook timeline
 *
 * @since Facebook SDK v2.0
 * @param Object options
 * @return Void
 */

facebook.ShareOpenGraph(Object options);

The options object accepts following parameters:

/**
 * Open Graph API action type
 *
 * @type: String
 * @default: NULL
 * @example: 'og.likes'
 */
action_type: ''

/**
 * Open Graph API action properties
 * in JSON key/value format
 *
 * @type: Object
 * @default: NULL
 * @example: {object: 'https://twitter.com/socialmedia_js'}
 */
action_properties: {}

/**
 * Callback function with
 * Graph API response object
 *
 * @type: Function
 * @default: NULL
 * @return: Graph API response Object
 */
callback: function(response) {}

# facebook.Feed({...})

/**
 * Share a link to Facebook timeline
 *
 * @deprecated Facebook SDK v2.0
 * @param Object options
 * @return Void
 */

facebook.Feed(Object options);

The options object accepts following parameters:

/**
 * Title of the share dialog
 *
 * @type: String
 * @default: NULL
 */
name: ''

/**
 * Absolute URL to share
 *
 * @type: String
 * @default: NULL
 */
link: ''

/**
 * Absolute URL to an image
 * to be dislayed in share dialog
 *
 * @type: String
 * @default: NULL
 */
picture: ''

/**
 * Caption to be dislayed in share dialog
 *
 * @type: String
 * @default: NULL
 */
caption: ''

/**
 * Description to be dislayed in share dialog
 *
 * @type: String
 * @default: NULL
 */
description: ''

/**
 * Callback function with
 * Graph API response object
 *
 * @type: Function
 * @default: NULL
 * @return: Graph API response Object
 */
callback: function(response) {}

# facebook.scroll({...})

/**
 * Scroll a Facebook Canvas
 *
 * @param Object options
 * @return Void
 */

facebook.scroll(Object options);

The options object accepts following parameters:

/**
 * Horizontal position to scroll to
 *
 * @type: Integer
 * @default: NULL
 */
x: 0

/**
 * Vertical position to scroll to
 *
 * @type: Integer
 * @default: NULL
 */
y: 0

# facebook.setSize({...})

/**
 * Set a default size for Facebook Canvas
 *
 * @param Object options
 * @return Void
 */

facebook.setSize(Object options);

The options object accepts following parameters:

/**
 * Width of the Facebook Canvas
 *
 * @type: Integer
 * @default: NULL
 */
width: 0

/**
 * Height of the Facebook Canvas
 *
 * @type: Integer
 * @default: NULL
 */
height: 0

References:

  1. Read more about frictionlessRequests
  2. Facebook JavaScript SDK
  3. Facebook SDK FB.ui

Next: Twitter

Analytics

Clone this wiki locally