Plus Service

The Plus service allows you to use the Google+ API in Apps Script. This API allows Google+ users programmatic access to their circles, posts, and comments.

Reference

For detailed information on this service, see the reference documentation for the Google+ API. Like all advanced services in Apps Script, the Plus service uses the same objects, methods, and parameters as the public API.

Sample code

The sample code below uses version 1 of the API.

Open code in new window

Get a list of people in the user's circles

This sample logs all of the people in the user's Google+ circles. Notice the use of page tokens to access the full list of results.

function getPeople() {
  var userId = 'me';
  var people, pageToken;
  do {
    people = Plus.People.list(userId, 'visible', {
      pageToken: pageToken
    });
    if (people.items) {
      for (var i = 0; i < people.items.length; i++) {
        var person = people.items[i];
        Logger.log(person.displayName);
      }
    } else {
      Logger.log('No people in your visible circles.');
    }
    pageToken = people.nextPageToken;
  } while (pageToken);
}

Get a list of the user's posts

This sample logs the titles of 10 posts the user has posted on their stream. For each post, it also logs the first 20 comments, if they exist.

function getPosts() {
  var userId = 'me';
  var posts, pageToken;
  do {
    posts = Plus.Activities.list(userId, 'public', {
      maxResults: 10,
      pageToken: pageToken
    });
    if (posts.items) {
      for (var i = 0; i < posts.items.length; i++) {
        var post = posts.items[i];
        Logger.log(post.title);
        var comments = Plus.Comments.list(post.id);
        if (comments.items) {
          for (var j = 0; j < comments.items.length; j++) {
            var comment = comments.items[j];
            Logger.log(comment.actor.displayName + ': ' +
                comment.object.content);
          }
        }
      }
    } else {
      Logger.log('No posts found.');
    }
    pageToken = posts.pageToken;
  } while (pageToken);
}

Send feedback about...

Apps Script
Apps Script