Table of contents
Description
Connects the user to a specified* social network. Technically speaking, a connection is an established session with the social network and it expires according to the social network's 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 which to connect is specified using the "provider" required parameter. You can find more details in the parameter description below.
If the user is logged in to the Gigya service:
- Gigya 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.
- Gigya 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 automatically be available.
Note: This method is also supported in our REST API. If you wish to execute this method from your server, please refer to REST API > socialize.addConnection.
Supporting Providers
The following providers currently support this operation: Facebook, Twitter, Yahoo, Microsoft Messenger, LinkedIn, Myspace, Orkut, Google+, Renren, Kaixin, Vkontakte, mixi, Yahoo Japan.
Syntax
gigya.socialize.addConnection(params)
Method Parameters
The following table lists the params object members:
| Required | Name | Type | Description |
| Required | provider | string | The provider to which to connect. The optional values for this parameter are:'facebook', 'twitter', 'yahoo', 'messenger', 'linkedin', 'myspace', 'orkut', 'google-plus', 'renren', 'kaixin', 'vkontakte', 'mixi', 'yahoojapan'. |
| Optional | sessionExpiration | integer | This parameter defines the time in seconds that Gigya should keep the social network session valid for the user. To end the session when the browser closes, please assign the value '0'. If this parameter is not specified the session will be valid forever. |
| facebookExtraPermissions | string | A comma-delimited list of Facebook-extended permissions to request from the user. This parameter gives the possibility to request extended permissions in addition to the permissions that Gigya already requests. Please refer to Facebook's extended permissions page for the complete list of permissions. For example, if you wish to RSVP to events on the user's behalf and to to send text messages to the user, define: facebookExtraPermissions : "rsvp_event,sms" Note: the value of this parameter overrides the value of the identical parameter in the global configuration object. | |
| googleExtraPermissions | string | This parameter gives the possibility to request extended permissions in addition to the permissions that Gigya is already requesting. The supported values are: "wallet" - for Google wallet permissions. | |
| authFlow | string | Using this parameter you may specify that the adding connection flow will use page redirects instead of using a popup. This gives a solution for environments where popups are unavailable (e.g. mobile web view controls). This parameter accepts two values:
| |
| redirectURL | string | This parameter is relevant only if the authFlow parameter is set to "redirect" (see above). Set this parameter with a URL to which to redirect the user when the adding connection process has successfully completed. The following additional parameters are appended to the URL string: UID, UIDSig, timestamp, loginProvider, loginProviderUID, nickname, photoURL, thumbnailURL, firstName, lastName, gender, birthDay, birthMonth, birthYear, email, country, state, city, zip, profileURL, proxiedEmail, provider. These parameters are equivalent to the User object fields. Please find the parameters' description in the User object reference page. When redirectURL is explicitly defined by the partner the user object fields should always be sent with the redirect regardless of the authFlow mode. Note: we strongly advise providing a secure Https URL. | |
| redirectMethod | string | This parameter is only applicable when redirectURL is specified and it determines how the user info data is passed to the redirectURLs. This parameter accepts two values:
| |
| callback | function | A reference to a callback function. Gigya calls 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 that is passed to the callback function. | |
| cid | string | A string of maximum 100 characters length. This string is 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 global configuration object. | |
| context | object | A developer-created object that is passed back unchanged to the application as one of the fields in the response object. | |
| extraFields | string | This parameter accepts a comma-separated list of additional data fields to retrieve. The current valid values are: languages, address, phones, education, honors, publications, patents, certifications, professionalHeadline, bio, industry, specialties, work, skills, religion, politicalView, interestedIn, relationshipStatus, hometown, favorites, likes, username, locale, verified, irank and timezone. Note: Before your application can retrieve Facebook data, the user must grant your application with access. Please make sure you have checked the check boxes that enable retrieving the relevant fields from Facebook in the Permissions page on Gigya's website. You may find more information in the Facebook Permissions section of our guide. | |
| actionAttributes | JSON object | In Gamification your users receive points for actions they perform on your site, in this case adding a connection grants the user points. Action Attributes may be used to annotate actions with additional information, such as the section of the web site that generated the action. If you set here the actionAttributes, each time a user adds a connection, the action also receives an attribute, for example "tv-show":"glee", which can mean that the action was performed on the "Glee" page of the site. These action attributes are later used to display the GM Plugins filtered according to a certain attribute. For example, you can show the Leaderboard plugin only for top users on the "Glee" page. This parameter receives a JSON object, comprised of a set or sets of a key (category) and a value or values, i.e.: "tv-show": ["glee", "30rock"], |
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. |
| user | User object | A User object with updated information for the current user. |
Triggered Global Event
By using this method, the following global event is triggered: onConnectionAdded. To register an event handler use the socialize.addEventHandlers API method. Please refer to the onConnectionAdded event data. Refer to the Events page in the Developer Guide to learn more about how to handle events generated by the Gigya service.
Code Sample
function printResponse(response) {
if ( response.errorCode == 0 ) {
var user = response.user;
var msg = 'User '+user.nickname + ' is ' +user.age + ' years old';
alert(msg);
}
else {
alert('Error: ' + response.errorMessage);
}
}
gigya.socialize.addConnection({callback:printResponse, provider:'facebook'}); 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.

Comments