Google+ Platform

Comments: list

List all of the comments for an activity. Try it now or see an example.

For large collections, results are paginated.

Request

HTTP request

GET https://www.googleapis.com/plus/v1/activities/activityId/comments

Parameters

Parameter name Value Description
Required parameters
activityId string The ID of the activity to get comments for.
Optional parameters
maxResults unsigned integer The maximum number of comments to include in the response, which is used for paging. For any response, the actual number returned might be less than the specified maxResults. Acceptable values are 0 to 500, inclusive. (Default: 20)
pageToken string The continuation token, which is used to page through large result sets. To get the next page of results, set this parameter to the value of "nextPageToken" from the previous response.
sortOrder string The order in which to sort the list of comments.

Acceptable values are:
  • "ascending": Sort oldest comments first. (default)
  • "descending": Sort newest comments first.

Request body

Do not supply a request body with this method.

Response

If successful, this method returns a response body with the following structure:

{
  "kind": "plus#commentFeed",
  "etag": etag,
  "nextPageToken": string,
  "nextLink": string,
  "title": string,
  "updated": datetime,
  "id": string,
  "items": [
    comments Resource
  ]
}
Property name Value Description Notes
kind string Identifies this resource as a collection of comments. Value: "plus#commentFeed".
nextPageToken string The continuation token, which is used to page through large result sets. Provide this value in a subsequent request to return the next page of results.
title string The title of this collection of comments.
updated datetime The time at which this collection of comments was last updated. Formatted as an RFC 3339 timestamp.
id string The ID of this collection of comments.
items[] list The comments in this page of results.
etag etag ETag of this response for caching purposes.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library

// This sample assumes a client object has been created.
// To learn more about creating a client, check out the starter:
//  https://developers.google.com/+/quickstart/java

Plus.Comments.List listComments = plus.comments().list(activityId);
listComments.setMaxResults(5L);

CommentFeed commentFeed = listComments.execute();
List<Comment> comments = commentFeed.getItems();

// Loop through until we arrive at an empty page
while (comments != null) {
  for (Comment comment : comments) {
    System.out.println(comment.getActor().getDisplayName() + " commented " +
            comment.getObject().getContent());
  }

  // We will know we are on the last page when the next page token is null.
  // If this is the case, break.
  if (commentFeed.getNextPageToken() == null) {
    break;
  }

  // Prepare the next page of results
  listComments.setPageToken(commentFeed.getNextPageToken());

  // Execute and process the next page request
  commentFeed = listComments.execute();
  comments = commentFeed.getItems();
}

PHP

Uses the PHP client library

# This sample assumes a client object has been created.
# To learn more about creating a client, check out the starter:
#  https://developers.google.com/+/quickstart/php

$optParams = array('maxResults' => 100);
$comments = $plus->comments->listComments('z12gtjhq3qn2xxl2o224exwiqruvtda0i', 
    $optParams);
foreach($comments['items'] as $comment) {
  print "{$comment['id']}, {$comment['object']['content']}\n"; 
}

Python

Uses the Python client library

# This sample assumes a client object has been created.
# To learn more about creating a client, check out the starter:
#  https://developers.google.com/+/quickstart/python

comments_resource = service.comments()
comments_document = comments_resource.list( \
    maxResults=10,activityId=activity_id).execute()

if 'items' in comments_document:
  print 'got page with %d' % len( comments_document['items'] )
  for comment in comments_document['items']:
    print comment['id'], comment['object']['content']

Ruby

Uses the Ruby client library

# This sample assumes a client object has been created.
# To learn more about creating a client, check out the starter:
#  https://developers.google.com/+/quickstart/ruby

status, headers, body = client.execute(
  plus.comments.list,
  {'activityId' => id, 'maxResults' => '10'})

return status if status != 200

response = JSON.parse(body[0])

comments = response[ 'items' ]

# Print out the collected comments
if ( !comments.nil? )
  for comment in comments
    puts "Comment: #{comment['id']} with content #{comment['object']['content']}"
  end
end

Go

Uses the Go client library

comments, err := plusService.Comments.List(activityId).Do()

JavaScript

Uses the JavaScript client library

// This sample assumes a client object has been created.
// To learn more about creating a client, check out the starter:
//  https://developers.google.com/+/quickstart/javascript
var request = gapi.client.plus.comments.list({
'activityId' : activityId }); request.execute(function(resp) { var numItems = resp.items.length; for (var i = 0; i < numItems; i++) { console.log(resp.items[i].actor.displayName + ' commented: ' + resp.items[i].object.content); } });

Try it!

Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.