Gigya Job Openings

comments.getComments JS

Skip to end of metadata
Go to start of metadata

Description

 

The method retrieves the comments in a specified comments stream. The comments that are retrieved are approved comments as well as ones that have approved replies.
 

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 > comments.getComments.

 

Syntax

 

 

Parameters

The following table lists the available parameters:

RequiredNameTypeDescription
categoryIDstringThe identifier of the comments category from which to retrieve the comments.
streamIDstringThe identifier of the comments stream from which to retrieve the comments.
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.
contextobject
A developer-created object that is passed back unchanged to the application as one of the fields in the response object.
includeStreamInfoBooleanThis parameter specifies whether to include a stream information object in the response. The default value is ' false   ' . When set to ' true ' the response to the method will include the  StreamInfo object .
includeUIDBooleanIndicates whether the UID of the commenter will be included in the returned object per comment. The default value is 'false'.
includeUserOptionsBooleanThis parameter specifies whether to include a user options object in the response. The default is ' false '. When set to ' true ' the response to the method will include the UserOptions object.
includeUserCommentsBooleanIndicates whether all the comments posted by the user to this stream will be included in the returned response. In reviews mode the default value of this parameter is true, in comments mode the default is false.
langstringThe language to which comment placeholder texts, such as "This comment has been deleted", should be translated. If this parameter is not passed, the language for translation is detected automatically based on the language in which the other comments are written.
pinnedCommentIDstringA comment ID from the stream specified by streamID. This parameter will assure that the comment thread will be included in the response, at the begining of the comments array, followed by the other comments in natural order. 
  Note : the pinned comment thread is not counted by the threadLimit.
sortstringThe comments may be sorted in one of the following orders:
  • "dateDesc" - the first comment is the latest one. The comments are sorted by the timestamp of the root comment.
  • "dateAsc" - the first comment is the first created (oldest). The comments are sorted by the timestamp of the root comment.
  • "lastReply" - the first comment is the the comment with the latest reply. The comments are sorted by the timestamp of their latest reply.
  • "ratingDesc" - the first comment is the latest updated comment/reply. The comments are sorted by the timestamp of their latest reply.
  • "ratingAsc" - the comments are sorted by the overall rating value, the first comment is the one that gave lowest rating.
  • "votesDesc" - The first comment is the one that has the highest votes. The comments are sorted by the overall votes value (positive votes minus negative votes) of the root comment in each thread.
  • "votesAsc" - The first comment is the one that has the lowest votes. The comments are sorted by the overall votes value (positive votes minus negative votes) of the root comment in each thread.
startstringDefines what should be the starting point of the comments to retrieve. The purpose of this parameter is pagination of the comments. Use threadLimit parameter to define how many comments per page. For the first page don't set the start parameter. The response includes a next field, which is a pointer to the starting point of the next page. Set the start parameter with the value of the next field received in the response of the previous getComments request.
tagsarrayThis parameter is a strings array representing list of tags, e.g.: ["tag_a","tag_b"]. The tags are used to filter comments, only comments that match the tags are to be retrieved.
threadLimitintegerThe maximum number of comment threads to retrieve. If you don't give this parameter a value, the value will be taken from the comment category thread limit that is set in the  Comments Settings  page of Gigya's site. You can change the comment category thread limit in the  Comments Settings  page or override it by using this parameter.
threadDepthintegerThe maximum depth of replies per comments thread to retrieve.
Note: with pinnedCommentID,  if the pinned thread is bigger than the limit, it will not be returned even though pinned.
threadedBooleanIndicates whether the comments are threaded. The default value is true.

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.
commentsArray of
Comment objects
An array listing the comments. Each comment is represented by a JSON Comment object.
userCommentsArray of
Comment objects
When  includeUserComments  is true, the response includes an array of all the comments posted by the user to this stream; each comment is represented by a JSON Comment object. In addition to the regular fields of the Comment object, the following fields are returned in the response of this method:
  • categoryID  - the category ID of the retrieved comment
  • streamID  -  the stream ID of the retrieved comment
commentCountintegerThe number of returned comments.
threadCountintegerThe number of returned comment threads.
hasMoreBooleanSpecifies whether there are more comments that were not returned within this response.
nextstringA pointer to the starting point of the next comments page. The purpose of this field is pagination of the comments. Use this field as the value of the 'start' parameter of the next getComments request, thus retrieving the next comments and avoid retrieving the same comments again.
streamInfoStream info objectA JSON object containing meta information of the requested commenting stream. This object is available in the response only if the "includeStreamInfo" parameter is set to 'true' in the request.
userOptionsJSON objectA JSON object containing meta information of a comments user. This object is available in the response only if the "includeUserOptions" parameter is set to 'true' in the request The object includes the following fields: 
  • replyNotifications  - the value may be either "disabled" or "immediate". When "immediate" it means that the user receives notifications of replies to his comments, in this way "following" his comments.
  • notificationsEmail  - the email address to which the notifications are sent.

Code Sample

function printResponse(response) {  
    if (response.errorCode == 0) {             
        if (null!=response.comments && response.comments.length>0) {        
            var msg = "The first 3 comments are:\n\n";   
            for (var index in response.comments) {     
                   msg += "Comment " + index + ": " + response.comments[index].commentText;
                   msg += "\n  Written by: " + response.comments[index].sender.name + "\n\n";
            }
            alert(msg);
        }
        else {
            alert('No comments were returned');
        }
    } else {
        alert('Error :' + response.errorMessage);
    }
};

var params = {
    categoryID: "12345", 
    streamID: "abc",
    callback: printResponse,
    threadLimit: 3
};

gigya.comments.getComments(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.