A collection of useful social media provider utilities. Currently, this module only supports Twitter and the following features:
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' });
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
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();
Initializes an OAuth session to the service provider. If a previous access token exists, it will be loaded.
OAuth session settings.
Site to access. Only 'twitter' is working.
Default: 'twitter'Shared secret used to authenticate the key.
Key used to identify the client to the service provider.
Instance of social to make subsequent API calls.
Returns 'true' if the client is authorized by the service provider.
Returns 'true' if authorized else 'false'.