Skip to content

Facebook

Jabran Rafique edited this page Apr 9, 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'

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
 *
 * @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.2'

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

/**
 * Facebook Canvas autogrow on content update
 *
 * @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);

String title, String message, Array to, Array exclude_ids, Int max_recipients, Object data, Function callback

Pay with Facebook.

facebook.Pay({
	String product, // Absolute URL
	Function callback
});

// callback response contains successful transaction data

Send a link.

facebook.Send({
	String link // Absolute URL
});

Share a link to Facebook Timeline.

Available since v2.0

facebook.Share({
	String href, // Absolute URL
	Function callback
});

// onSuccess response contains successful request data
// onFail response contains failed request data

Share an Open Graph API object to Facebook Timeline.

Available since v2.0

facebook.ShareOpenGraph({
	String action_type, // Open Graph API action type e.g. og.likes
	Object action_properties, // JSON string in key/value pair e.g. { object: 'http://git.io/socialmedia' }
	Function callback
});

// onSuccess response contains successful request data
// onFail response contains failed request data

Share a link to Facebook Timeline. (Using legacy Share dialog)

Available only with v1.0

facebook.Feed({
	String name, // Previously title
	String link, // Absolute URL
	String picture, // Absolute URL (Previously image)
	String caption,
	String description,
	Function callback
});

// onSuccess response contains successful request data
// onFail response contains failed request data

Scroll the Facebook Canvas.

facebook.scroll({
	int x, int y
});

Set Facebook Canvas size. Default size 810x800.

facebook.setSize({
	int width,
	int height
});

References:

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

Next: Twitter

Clone this wiki locally