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.

To report issues and find other support, see the Google+ support guide.

Sample code

The sample code below uses version 1 of the API.

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.

advanced/googlePlus.gs
/**
 * The following example demonstrates how to retrieve a list of the people
 * in the user's Google+ circles.
 */
function getPeople() {
  var userId = 'me';
  var people;
  var 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.

advanced/googlePlus.gs
/**
 * The following example demonstrates how to list a user's posts. The returned
 * results contain a brief summary of the posts, including a list of comments
 * made on the post.
 */
function getPosts() {
  var userId = 'me';
  var posts;
  var 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);
}

发送以下问题的反馈:

此网页
Apps Script
Apps Script
需要帮助?请访问我们的支持页面