Google+ Platform

Activities: search

Search public activities. Try it now or see an example.

For large result sets, results are paginated. For the most up-to-date search results, do not use a pageToken older than five minutes. Instead, restart pagination by repeating the original request (omitting pageToken).

To search people, see people search.

Request

HTTP request

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

Parameters

Parameter name Value Description
Required parameters
query string Full-text search query string.
Optional parameters
language string Specify the preferred language to search with. See search language codes for available values.
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 20, inclusive. (Default: 10)
orderBy string Specifies how to order search results.

Acceptable values are:
  • "best": Sort activities by relevance to the user, most relevant first.
  • "recent": Sort activities by published date, most recent first. (default)
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. This token can be of any length.

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.Search searchActivities = plus.activities().search("awesome");
searchActivities.setMaxResults(5L);

ActivityFeed activityFeed = searchActivities.execute();
List<Activity> activities = activityFeed.getItems();

// Loop through until we arrive at an empty page
int pageNumber = 1;
while (activities != null && pageNumber <= 2) {
  pageNumber++;

  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
  searchActivities.setPageToken(activityFeed.getNextPageToken());

  // Execute and process the next page request
  activityFeed = searchActivities.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

$params = array(
  'orderBy' => 'best',
  'maxResults' => '20',
  'query' => 'Google+ API'
);
$results = $plus->activities->search($params);
foreach($results['items'] as $result) {
  print "Result: {$result['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()
activities_document = activities_resource.search( \
    maxResults=10,orderBy='best',query='wolff').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']

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.search,
  {'query' => 'pizza'})

return status if status != 200

response = JSON.parse(body[0])

activities = response[ 'items' ]

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

.NET

Uses the .NET 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/csharp

ActivitiesResource.SearchRequest searchRequest = plusService.Activities.Search(searchStr);
ActivityFeed activityFeed = searchRequest.Fetch();

Go

Uses the Go client library

activities, err := plusService.Activities.Search("Awesome").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.search({
  'query' : 'Awesome'
});

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.