Gigya Job Openings

socialize.waitForService JS

Skip to end of metadata
Go to start of metadata



This utility method allows you to wait for a service to finish its initialization process before using it. When the required service is ready to be used the callback function is executed. If the service is already ready when you call the waitForService method, then the callback is executed immediately.

Use this method as a wrap-around the service usage, for example:

gigya.socialize.waitForService({service: 'facebook', callback: function(response) {
        // Service is ready
        // Use the service here 
    } });


Using Facebook JS SDK

In order to use the Facebook JS SDK the following requirements must be fulfilled:

  1. Define a CNAME entry in your DNS server: specify a new subdomain in your site and point it to
  2. In the Gigya's Site setup page, make sure to configure a domain alias (CNAME) and in Gigya's Permissions page, enable Native SDK.
  3. Open an external application in Facebook. When configuring the external application make sure to follow the instructions for sites using a domain alias, namely, paste your CNAME subdomain instead of in all the places that require a callback URL.
  4. In your page, when loading gigya.js, make sure to pass your APIKey as a parameter (read more in Gigya Basics):

    <script type="text/javascript" src="" ></script>  
  5. Use the socialize.waitForService method, to ensure that the Facebook service is ready to be used (see the code sample below).






The following table lists the available parameters:

servicestringThe service for which to wait. Currently only "facebook" is supported for use with this parameter.
callbackfunctionA reference to a callback function. Gigya calls the specified function along with the response when the requested service is ready to be used. If the service is already ready when you call the API method, then the callback is executed immediately.
The callback function should be defined with the following signature: functionName(response)
The "Response object Data Members" table below provides specification of the data that is passed to the callback function.
A developer-created object that is passed back unchanged to the application as one of the fields in the response object.


Response Object Data Members

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 Response Codes and Errors table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
callId string Unique identifier of the transaction, for debugging purposes.
context object The context object passed by the application as a parameter to the API method, or null if no context object has been passed.

Triggered Global Events

See Events for more infromation.

facebookLoaded Event Data

eventNamestringThe name of the event: 'facebookLoaded'.
isLoggedInBooleanSpecifies whether the user is logged in.
isConnectedBooleanSpecifies whether the user is connected.


Code Sample

gigya.socialize.waitForService({service: 'facebook', callback: function(response) {
        // facebook Service is ready to be used. Facebook API usage comes here:
        FB.ui( {method: 'stream.share'}, function(){} ); 
} });


  • 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.
  • To run the code on your own domain, add your Gigya API key to the gigya.js URL. A Gigya API key can be obtained on the Site Dashboard page on Gigya's website. Please make sure that the domain from which you are loading the page is the same domain name that you used for generating the API key.
  • In some cases it is necessary to connect/login the user to a provider ? prior to calling the API method. You can learn more in the Social Login guide.