Description
Connects a user to a specified* social network. Technically speaking a connection is equivalent to an established session with the social network and it may expire according to the social network policy. A valid and active connection will give your site access to the user's social graph and ability to perform various social actions, such as publishing a newsfeed report to the connected social network.
* The social network to connect to is specified using the "provider" required parameter. You may find more details in the parameter description below.
Note:
If the user is logged in to Gigya Socialize:
- Socialize will automatically link between the connected social network account and the user's site account. As a consequence, from now on the user will be able to log into his site account using this social network.
- Socialize will associate the connection with the user's account. This means that if the user logs in on different computers using the same account, the connection will be automatically available.
If the user is not logged in, the connection will be associated with the current user on the current computer using a cookie.
Supporting Providers
This operation currently supported by the following providers: Facebook, Myspace, Twitter, Yahoo, LinkedIn.
Syntax
gigya.services.socialize.connect(conf,params)
Method parameters
conf object
Please refer to the Conf object page for full specifications.
params object members
| Required | Name | Type | Description |
| Required | provider | string | The provider to connect to. The optional values for this parameter are: 'facebook', 'myspace', 'twitter', 'yahoo', 'linkedin'. |
| Optional | useFacebookConnect | boolean | Assigning "true" to this parameter, will cause Gigya Socialize to pop-up Facebook Connect UI when connecting to the user's Facebook account (i.e. when the user presses the Facebook button of the Connect UI). You may find more information about the subject in Using Facebook Connect section in the Developer's Guide. Note: this parameter is not supported in ActionScript environment. |
| | invite | Invite object | If this parameter is specified then the "Invite" dialog will be displayed when a user connects to Facebook. You may find more information about the subject in Inviting Friends section in the Developer's Guide. |
| | shortURLs | string | This parameter is relevant only if you use the 'invite' parameter defined above. Using this parameter you may determine whether to use Gigya's URL shortening service for URLs, which are published through this method. The optional values for this parameter are: - 'always' (default): always shorten URLs.
- 'whenRequired': shorten URLs when needed - when posting to Twitter, LinkedIn, MySpace and Yahoo where the status update is limited to 140 char.
- 'never' - never shorten URLs.
When Gigya's URL shortening service is active, Gigya tracks all the traffic coming from the distributed URLs. In such case, 'Referred Traffic' reports will be available to you. Note: the value of this parameter overrides the value of the identical parameter in the Conf object. |
| 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 |
| status | string | The result code of the operation ('OK' indicates success, any other string indicates failure). |
| statusMessage | string | A short textual description of an error, associated with the status, 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. |
| user | User object | A User object with updated information for the current user. |
Code Sample
var conf = {
APIKey:'2_fA4cZD0cEmxKUjDdNai8hyK4fZ-Jq7w4qm1x-pkS-7E6NDm90gAmrdcugVoaewUS'
};
function printResponse(response) {
if ( response['status'] == 'OK' ) {
var user = response['user'];
var msg = 'User '+user['nickname'] + ' is ' +user['age'] + ' years old';
alert(msg);
}
else {
alert('Error: ' + response['statusMessage']);
}
}
gigya.services.socialize.connect(conf,{callback:printResponse, provider:'facebook'});
function printResponse(response:Object):void {
if ( response['status'] == 'OK' ) {
var user:Object = response['user'];
var msg:String = 'User '+user['nickname'] + ' is ' +user['age'] + ' years old';
trace(msg);
}
else {
trace('Error: ' + response['statusMessage']);
}
}
function connect():void {
var conf:Object = {
mcRoot:this.root,
APIKey:'2_fA4cZD0cEmxKUjDdNai8hyK4fZ-Jq7w4qm1x-pkS-7E6NDm90gAmrdcugVoaewUS'
};
gigya.services.socialize.connect(conf,{callback:printResponse, provider:'facebook'});
}
Notes:
a. This sample is not meant to be fully functional code. For brevity only the code required to demonstrate the API call itself is presented.
b. The API key in the sample will only work on
http://localhost/...
You should change it to your own domain if you would like to test this code in any other environment.
c. Best practice is, to define one global
conf object and use it throughout the application.