You are not logged in.   Log in | Register

socialize.getFriendsInfo

From $1

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 will return the user's friends from all the connected providers which support friends feature.

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

This operation currently supported by the following providers: Facebook, Myspace, Twitter, Yahoo, LinkedIn.

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

Gigya Socialize supports a mechanism to verify the authenticity of the getFriendsInfo process.  

If the Conf object's "signIDs" field is set to "true", Gigya "signs" each friend with a cryptographic signature, to prevent fraud.

Your site will receive in getFriendsInfo's callback function the list of friends as part of the response object (please refer to the Response object Data Members table below). Each Friend object has a cryptographic signature (friendshipSig data member) provided by Gigya.

We highly recommend verifying the authenticity of the signature to prove that it is indeed originating from Gigya, rather than somewhere else.

To learn more about this subject, please refer to the Cryptographic Signatures section in the Security page of the Developer's Guide.

 

Syntax

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

 

Method parameters

conf object

Please refer to the Conf object page for full specifications.

params object members

Required Name Type Description
Optional detailLevel string This 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.

  friends Collection A collection of Friend objects representing a list of friends (as returned by the Friends Selector Widget). In case 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 that were selected using the Friend Selector Widget.
  UIDs string A comma separated list of UIDs of friends of the current user to get the information for.
Note: If both friends and UIDs are missing the method will return all the friends of the current user.
  siteUsersOnly boolean If the parameter is set to true then only the friends which are also site users are returned. The default value of this parameter is false.

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.

enabledProviders string A comma delimited list of provider names to include in the method execution. This parameter gives the possibility to apply this method to only 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 provides).
For example, if you would like the method to apply only to Facebook and Twitter, define: enabledProviders="facebook,twitter".
Note: the value of this parameter overrides the value of the identical parameter in the Conf object.
Valid provider names include: 'facebook', 'myspace', 'twitter', 'yahoo', 'linkedin'.
  disabledProviders string A comma delimited list of provider names to exclude in the method execution. This parameter gives the possibility to specify provides that you don't want this method to apply to. If you do not set this parameter, by default, no provider is disabled (i.e. the method applies to all connected provides).
For example, if you would like the method to apply to all providers except Google and Twitter, define: disabledProviders="google,twitter".
Note: the value of this parameter overrides the value of the identical parameter in the Conf object.
Valid provider names include: 'facebook', 'myspace', 'twitter', 'yahoo', 'linkedin'.
  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.
friends Collection  A collection of Friend object, corresponding to the list of friends of the current user on all the social networks the user is connected to.
If either the 'friends' or 'UIDs' input parameters are provided in the function call, only the specified friends will be retrieved.
UIDs string A comma separated list of UIDs of friends of the current user.
Note: The UIDs list is equivalent to the 'friends' Collection field.

 

Code Sample

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

function printResponse(response) {  
    if ( response.errorCode == 0 ) {             
        var myFriends = response['friends'].asArray();          
        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',
    context:context, 
    UIDs:'_gid_3VgBvTtCGqDTEtcZMGL08w==,_gid_1FyT4hKPcD+oCM121MM+Q==',
    callback:printResponse
};

gigya.services.socialize.getFriendsInfo(conf,params);
function printResponse(response:Object):void {  
    if ( response.errorCode == 0) {             
        var myFriends:Array = response['friends'].asArray();          
        if ( null!=myFriends && myFriends.length>0) {        
            var msg:String = response['context']['myFriendsTitle'] + '\n\n';        
            for (var index:String in myFriends) {
                var currFriend:Object = myFriends[index];
                msg += currFriend['name'] + '('+currFriend['nickname']+') - '+ currFriend['photoURL']+ ':\n' ;                 
            }            
            trace(msg);
        }
        else {
            trace('No friends were returned');
        }
    }
    else {
        trace('Error :' + response.errorMessage);
    }
}

function getFriendsInfo():void {
	var conf:Object = { // Note: best practice is, to define one global conf object and use it throughout the application
		mcRoot:this.root,
		APIKey:'2_fA4cZD0cEmxKUjDdNai8hyK4fZ-Jq7w4qm1x-pkS-7E6NDm90gAmrdcugVoaewUS'
	};

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

	var params:Object = {
		detailLevel:'extended',
		context:context, 
		UIDs:'_gid_3VgBvTtCGqDTEtcZMGL08w==,_gid_1FyT4hKPcD+oCM121MM+Q==',
		callback:printResponse
	};

	gigya.services.socialize.getFriendsInfo(conf,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.
  • 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.

 

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

Tags:
Files (0)