Alloy.builtins.social

A collection of useful social media provider utilities. Currently, this module only supports Twitter and the following features:

  • Logging into Twitter and authorizing the application through the OAuth protocol.
  • Posting tweets to the user's Twitter account.

To use the social builtin library, require it with the alloy root directory in your require call. For example:

var social = require('alloy/social').create({ consumerSecret: 'consumer-secret', consumerKey: 'consumer-key' });

Login and Authorization

To use a social media provider, a user must log in and authorize the application to perform certain actions, such as accessing profile information or posting messages.

Call authorize to prompt the user to login and authorize the application. For Twitter, a dialog box will appear asking the user for their permission and login credentials.

Before calling authorize, the application will need a consumer key and secret provided by the social media service provider for the OAuth protocol, used when calling create. For Twitter, these are provided when registering an application: https://dev.twitter.com/apps/new

Example

This example authorizes the application, posts a message to the user's Twitter account, then deauthorizes the application.

// If not authorized, get authorization from the user
if(!social.isAuthorized()) {
    social.authorize();
}

// Post a message

// Setup both callbacks for confirmation // Note: share() automatically calls authorize() so an explicit call as above is unnecessary social.share({ message: "Salut, Monde!", success: function(e) {alert('Success!')}, error: function(e) {alert('Error!')} });

// Deauthorize the application
social.deauthorize();
Defined By

Methods

Alloy.builtins.social
( [callback] )
Authorizes the client to the service provider to access user data. ...

Authorizes the client to the service provider to access user data. If successful, the client will receive an access token, which will be saved for future usage. Call this function after opening the parent view or else the authorize UI window will appear in the background behind the view and unusable to the user.

Parameters

  • callback : Function (optional)

    Callback function executed after successfully retrieving an access token.

Returns

  • void
Alloy.builtins.social
( settings ) : Object
Initializes an OAuth session to the service provider. ...

Initializes an OAuth session to the service provider. If a previous access token exists, it will be loaded.

Parameters

  • settings : ...*

    OAuth session settings.

    • site : String (optional)

      Site to access. Only 'twitter' is working.

      Default: 'twitter'
    • consumerSecret : String

      Shared secret used to authenticate the key.

    • consumerKey : String

      Key used to identify the client to the service provider.

Returns

  • Object

    Instance of social to make subsequent API calls.

Alloy.builtins.social
( )
Deauthorizes the client and clears the access token. ...

Deauthorizes the client and clears the access token.

Returns

  • void
Alloy.builtins.social
( ) : Boolean
Returns 'true' if the client is authorized by the service provider. ...

Returns 'true' if the client is authorized by the service provider.

Returns

  • Boolean

    Returns 'true' if authorized else 'false'.

Alloy.builtins.social
( options )
Sends an update to the service provider. ...

Sends an update to the service provider. Implicitly calls authorize() to authorize your app.

Parameters

  • options : ...*

    Update parameters.

    • message : String

      Message to send.

    • success : Function (optional)

      Callback function executed after a successful update.

    • error : Function (optional)

      Callback function executed after a failed update.

Returns

  • void