You are not logged in.   Log in | Register

socialize.addEventHandlers

From $1

Description

Gigya Socialize generates several global application events for various situations which are driven by user interactions.

Global application events are fired whenever the event they refer to occurs, regardless of what was the action that triggered the event.

This is in contrast to Widget events, which are only fired by the specific Widget they were configured on.

This method allows setting event handlers for each of the supported global events.

To learn more about how to handle events generated by Gigya socialize, please refer to the Events page in the Developer's Guide.

 

The following is a list of available global application events:

  • onLogin - Fired whenever a user is authenticated using either a call to login() or to showLoginUI().
  • onLogout - Fired whenever a user logs out using the logout() call.
  • onConnect - Fired whenever a user is connected to a provider?. This might be, for example, as a result of a call to connect() or the user editing his connections, etc.
  • onDisconnect - Fired whenever a user is disconnected from a provider. As above, this event will be fired regardless of what was the action that triggered it.

 

An Event Handler is a JavaScript function with the following signature:

functionName(eventObj)

The single argument - eventObj, contains information about the event and has different data fields for different events. In "Event Handlers - eventObj event data" below, you will find specification of the fields available in the eventObj for each event.

     

 

Syntax

gigya.services.socialize.addEventHandlers(conf,params)

 

Method parameters

conf object

Please refer to the Conf object page for full specifications.

params object members

Required Name Type Description
Optional onLogin function A reference to a function that will be called when the user is successfully authenticated by an external provider.
  onLogout function A reference to a function that will be called when the user has logged out.
  onConnect function A reference to a function that will be called when the user is successfully connected to a provider.
  onDisconnect function A reference to a function that will be called when the user disconnects from a provider.

callback function A reference to a callback function. Gigya will call the specified function along with the results of the API method when the API method completes.
The callback function should be defined with the following signature: functionName(response)
The "Response object Data Members" table below provides specification of the data which is passed to the callback function.
  cid string A string of maximum 100 characters length. This string will be associated with each transaction and will later appear on reports generated by Gigya, in the "Context ID" combo box. The cid allows you to associate the report information with your own internal data, for example, to identify a specific widget or page on your site/application. The "Context ID" combo box lets you filter the report data by site/application context.
Note: the value of this parameter overrides the value of the identical parameter in the Conf object.
  context object A developer-created object that will be passed back unchanged to the application as one of the fields in the response object.

 

Response object Data Members

Field Type Description
errorCode integer The result code of the operation. Code '0' indicates success, any other number indicates failure. For a complete list of error codes, see the Error Codes table.
errorMessage string A short textual description of an error, associated with the errorCode, for logging purposes.
operation string The name of the API method that generated this response.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.

 

Event Handlers - eventObj event data

The following tables specify the list of data fields available in the eventObj for each event.

onLogin event data

Field Type Description
eventName string The name of the event: "login".
context object The context object passed as parameter to the method, or null if no object was passed.
user User object User object with updated information for the current user.
signature string The cryptographic signature that should be used for login verification*.
timestamp string The GMT time of the login event in "yyyy-mm-dd HH:mm:ss" format where HH is in 24 hour time format. The timestamp should be used for login verification*.
UID string The User ID that should be used for login verification*.
Note: The UID string must be encoded using the encodeURIComponent() function, before sending it from your client to your server.
provider string The name of the provider that the user used in order to login.
* To learn more about login verification, please refer to the Cryptographic Signatures section in the Security page of the Developer's Guide.

 

onLogout event data

Field Type Description
eventName string The name of the event: "connect".
context object The context object passed as parameter to the method, or null if no object was passed.

  

onConnect event data

Field Type Description
eventName string The name of the event: "connect".
context object The context object passed as parameter to the method, or null if no object was passed.
user User object A User object with updated information for the current user.
provider string The name of the social network that the user connected to.

 

onDisconnect event data

Field Type Description
eventName string The name of the event: "disconnect".
context object The context object passed as parameter to the method, or null if no object was passed.
user User object User object with updated information for the current user.
provider string The name of the social network that the user disconnected from.

  

 

Code Sample

var confObj= {   
     APIKey:'2_fA4cZD0cEmxKUjDdNai8hyK4fZ-Jq7w4qm1x-pkS-7E6NDm90gAmrdcugVoaewUS'  
};  

function DisplayEventMessage(eventObj) {
    alert(eventObj.context.str+' '+eventObj.eventName);
}
 
gigya.services.socialize.addEventHandlers(confObj, { 
    context:{str:'congrats on your'}, 
    onLogin:DisplayEventMessage,
    onConnect:DisplayEventMessage
   }
);

gigya.services.socialize.addEventHandlers(confObj, { 
    context:{str:'sorry to see you'}, 
    onDisconnect:DisplayEventMessage
   }
);
function DisplayEventMessage(eventObj:Object):void {
    trace(eventObj.context.str+' '+eventObj.eventName);
}

function addEventHandlers():void {
	var confObj:Object = {   
		mcRoot:this.root,
		 APIKey:'2_fA4cZD0cEmxKUjDdNai8hyK4fZ-Jq7w4qm1x-pkS-7E6NDm90gAmrdcugVoaewUS'  
	}; 
 
	gigya.services.socialize.addEventHandlers(confObj, { 
		context:{str:'congrats on your'}, 
		onLogin:DisplayEventMessage,
		onConnect:DisplayEventMessage
	   }
	);

	gigya.services.socialize.addEventHandlers(confObj, { 
		context:{str:'sorry to see you'}, 
		onDisconnect:DisplayEventMessage
	   }
	);
}

Notes:
  • This sample is not meant to be fully functional code. For brevity's sake, only the code required for demonstrating the API call itself is presented.
  • The API key in the sample will only work on http://localhost/...
  • To run the code on your own domain, modify the API key in the example to your own API key. A Gigya API Key can be obtained on the Site Setup page on Gigya's website. Please make sure that the domain you are loading the page from is the same domain name that you used for generating the API Key.
  • In some cases it is necessary to connect the user to a provider? prior to calling the API method. For connecting the user to a provider, you may use the Connect API method call or the pre-built Connect Widget.
  • Best practice is, to define one global conf object and use it throughout the application.

Tags:
Files (0)