Google+ Platform

Activities: list

List all of the activities in the specified collection for a particular user. Try it now or see an example.

The collection parameter specifies which activities to list, such as public activities. For large collections, results are paginated.

If using the userId value "me", this method requires authentication using a token that has been granted the OAuth scope https://www.googleapis.com/auth/plus.login or https://www.googleapis.com/auth/plus.me. Read more about OAuth.

Request

HTTP request

GET https://www.googleapis.com/plus/v1/people/userId/activities/collection

Parameters

Parameter name Value Description
Required parameters
collection string The collection of activities to list.

Acceptable values are:
  • "public": All public activities created by the specified user.
userId string The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.
Optional parameters
maxResults unsigned integer The maximum number of activities 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 1 to 100, 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.

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#activityFeed",
  "etag": etag,
  "nextPageToken": string,
  "selfLink": string,
  "nextLink": string,
  "title": string,
  "updated": datetime,
  "id": string,
  "items": [
    activities Resource
  ]
}
Property name Value Description Notes
kind string Identifies this resource as a collection of activities. Value: "plus#activityFeed".
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 activities, which is a truncated portion of the content.
updated datetime The time at which this collection of activities was last updated. Formatted as an RFC 3339 timestamp.
id string The ID of this collection of activities. Deprecated.
items[] list The activities 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.Activities.List listActivities = plus.activities().list("me", "public");
listActivities.setMaxResults(5L);

// Execute the request for the first page
ActivityFeed activityFeed = listActivities.execute();

// Unwrap the request and extract the pieces we want
List<Activity> activities = activityFeed.getItems();

// Loop through until we arrive at an empty page
while (activities != null) {
  for (Activity activity : activities) {
    System.out.println("ID " + activity.getId() + " Content: " +
            activity.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 (activityFeed.getNextPageToken() == null) {
    break;
  }

  // Prepare to request the next page of activities
  listActivities.setPageToken(activityFeed.getNextPageToken());

  // Execute and process the next page request
  activityFeed = listActivities.execute();
  activities = activityFeed.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' => 5);
$activities = $plus->activities->listActivities('me', 'public', $optParams);
foreach ($activities['items'] as $activity) {
  $actor = $activity['actor'];
  print "{$actor['displayName']} says: {$activity['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 activities_resource = service.activities() request = activities_resource.list( userId='me', collection='public', maxResults='2') while request != None: activities_document = request.execute() if 'items' in activities_document: print 'got page with %d' % len( activities_document['items'] ) for activity in activities_document['items']: print activity['id'], activity['object']['content'] request = service.activities().list_next(request, activities_document) print "----------------------"

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.activities.list,
  {'userId' => 'me',
   'collection' => 'public',
   'maxResults' =>'3'})

return status if status != 200

response = JSON.parse(body[0])
activities = response['items']

# We have some activities, but we need to keep paging

old_next_page_token = nil
while response['nextPageToken'] do
  # Due to a known issue sometimes page tokens repeat. If they do you're at
  #   the end of the list.
  break if response['nextPageToken'] == old_next_page_token
  old_next_page_token = response['nextPageToken']

  status, headers, body = client.execute(
    plus.activities.list,
    {'userId' => 'me',
     'collection' => 'public',
     'maxResults' => '3',
     'pageToken' => response['nextPageToken']})

  response = JSON.parse(body[0])
  activities += response['items'] unless !response['items']
end

# Print out the collected activities
for activity in activities
  puts "Activity: #{activity['id']} " +
    "with title #{activity['title']} " +
    "with content #{activity['object']['content']}"
end

Go

Uses the Go client library

activities, err := plusService.Activities.List("me", "public").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.activities.list({
  'userId' : 'me',
  'collection' : 'public'
});

request.execute(function(resp) {
  var numItems = resp.items.length;
  for (var i = 0; i < numItems; i++) {
    console.log('ID: ' + resp.items[i].id + ' Content: ' +
      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.