socialize.getFriendsInfo JS

Skip to end of metadata
Go to start of metadata

Description

 

Returns information about friends of the current user. This method supports getting either basic or extended information for all or some of the user's friends. The method returns the user's friends from all the connected providers that support friends feature.
Note that retrieving friends' data should be requested explicitly by checking the appropriate checkbox in the console's permissions section. 

In some cases, you can use the getRawData API to retrieve data directly from the provider for information that is not natively provided by Gigya.

 

Important Notes:
Retrieving the list of friends from the different providers may be a lengthy operation, depending on the number of friends and the performance of each provider. Gigya begins retrieving the list to its cache immediately after the user logs in but if you call this method too soon after the login, the friends list may not be available yet. In this case the server will return statusCode 100 and errorCode 100001 which means: "Data pending". You may wait a while and retry the call or modify your application flow to not require this information immediately after the user logs in.
Please note, that since retreiving friends list is a lengthy operation, Gigya caches the friends list for 24 hours or until a successful login.

 

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.getFriendsInfo.

Supporting Providers

The following providers currently support this operation:

Facebook, TwitterYahoo, MicrosoftLinkedIn (Note: messenger has been replaced by microsoft, however, for backward compatibility, either can be used) 
, Google+FourSquare, Renren, Vkontakte, mixi, Yahoo JapanXing.

Note: Our definition of a 'friend' in Twitter, is a person who is both a 'follower' and is in the 'following' list of the current user.

Securing the getFriendsInfo Process

The Gigya service supports a mechanism to verify the authenticity of the getFriendsInfo process.
If the global configuration object's signIDs field is set to 'true', Gigya "signs" each friend with a cryptographic signature to prevent fraud.
As part of the response object, your site will receive the list of friends in the getFriendsInfo's callback function (please refer to the Response object Data Members table below). Each Friend object has a cryptographic signature (friendshipSignature data member) provided by Gigya.
We highly recommend verifying the authenticity of the signature to prove that it has indeed originated from Gigya rather than somewhere else.
To learn more about this subject, please refer to the Validate Friendship Signatures section in the Security page of the Developer's Guide.

 

Syntax

 

 

Parameters

The following table lists the available parameters:

RequiredNameTypeDescription
detailLevelstringThis field indicates whether to get basic or extended information about each friend. See the Friend object page for details on which fields are included for each detail level.

Allowed values are:
basic - Basic detail level. This is the default.
extended - Extended detail level.

friendsCollectionA collection of Friend objects representing a list of friends (as returned by the Friends Selector Plugin). When this parameter is provided, the function returns information only about the friends in the list.
This is useful if you want to get information about friends who were selected using the Friend Selector plugin.
UIDsstringDeprecated.
siteUsersOnlyBooleanIf the parameter is set to 'true' then only the friends who are also site users are returned. The default value of this parameter is 'false'.
callbackfunction
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.
enabledProvidersstring
A comma-delimited list of provider names to include in the method execution. This parameter gives the possibility to apply this method only to a subset of providers of your choice. If you do not set this parameter, by default all the providers are enabled (i.e., the method applies to all connected providers).
For example, if you would like the method to apply only to Twitter, define: enabledProviders: "twitter".
Valid provider names include:
'facebook', 'twitter', 'yahoo', 'microsoft', 'linkedin', 'qq', 'renren', 'sina' (Note: messenger has been replaced by microsoft, however, for backward compatibility, either can be used)'googleplus''foursquare', 'renren'', 'vkontakte', 'mixi', 'yahoojapan', 'xing'.

Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.

disabledProvidersstring
A comma-delimited list of provider names to exclude in the method execution. This parameter gives the possibility to specify providers to which you do not want this method to apply. If you do not set this parameter, by default, no provider is disabled (i.e., the method applies to all connected providers).
For example, if you would like the method to apply to all providers except Twitter, define: disabledProviders: "twitter".
Valid provider names include:
'facebook', 'twitter', 'yahoo', 'microsoft', 'linkedin', 'qq', 'renren', 'sina' (Note: messenger has been replaced by microsoft, however, for backward compatibility, either can be used)'googleplus', 'foursquare', 'renren', 'vkontakte', 'mixi', 'yahoojapan', 'xing'.

Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.

requiredCapabilitiesstringDeprecated.
cidstring
A string of maximum 100 characters length. The CID sets categories for transactions that can be used later for filtering 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. You should not define more than 100 different context IDs.

Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.

contextobject
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

FieldTypeDescription
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.
friendsCollectionA collection of Friend objects, corresponding to the list of friends of the current user on all the social networks to which the user is connected.
If either the 'friends' or 'UIDs' input parameters are provided in the function call, only the specified friends are retrieved.
UIDsstringA comma-separated list of UIDs of friends of the current user.
Note: The UIDs list is equivalent to the 'friends' collection field.

 

Code Sample

function printResponse(response) {   
    if ( response.errorCode == 0 ) {
        //convert the 'friends' collection into an array             
        var myFriends = response['friends'].asArray();  
        // Do some stuff with the info.         
        if ( null!=myFriends && myFriends.length>0) {        
            var msg = response['context']['myFriendsTitle'] + '\n\n';        
            for (var index in myFriends) {
                var currFriend = myFriends[index];
                msg += currFriend['name'] + '('+currFriend['nickname']+') - '+ currFriend['photoURL']+ ':\n' ;                 
            }            
            alert(msg);
        }
        else {
            alert('No friends were returned');
        }
    }
    else {
        alert('Error :' + response.errorMessage);
    }
}

var context = {
        myFriendsTitle : 'My friends are:'
};

var params = {
    //detailLevel = 'extended' is required to receive extended information such as birthdate, country etc'.
    detailLevel:'extended',
    context:context, 
    //User who's friends info we want to retrieve
    UIDs:'_gid_3VgBvTtCGqDTEtcZMGL08w==,_gid_1FyT4hKPcD+oCM121MM+Q==',
    callback:printResponse
};

gigya.socialize.getFriendsInfo(params);

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.
  • 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.

 

In the Get Friends Information page you will find a complete working example that uses the socialize.getFriendsInfo method. You may view the code, run it and view the outcome.