Google+ Domains Service

The Google+ Domains service allows you to use the Google+ Domains API in Apps Script. This API gives users the ability to interact with Google+ features such as posts, comments, and circles within their G Suite domain.

This service doesn't support the domain-wide delegation feature in the underlying API. This means that domain admininstrators are not able to run a script on behalf of users in their domain.

Reference

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

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

Sample code

The sample code below uses version 1 of the API.

Getting profiles

The following example demonstrates how to retrieve details from a user's Google+ profile.

advanced/googlePlusDomains.gs
/**
 * The following example demonstrates how to retrieve details from a user's
 * Google+ profile.
 */
function getProfile() {
  var userId = 'me';
  var profile = PlusDomains.People.get(userId);

  Logger.log('ID: %s', profile.id);
  Logger.log('Display name: %s', profile.displayName);
  Logger.log('Image URL: %s', profile.image.url);
  Logger.log('Profile URL: %s', profile.url);
}

Creating circles

The following example demonstrates how to create an empty circle for a user within your G Suite domain.

advanced/googlePlusDomains.gs
/**
 * The following example demonstrates how to create an empty circle for a user
 * within your G Suite domain.
 */
function createCircle() {
  var userId = 'me';
  var circle = PlusDomains.newCircle();
  circle.displayName = 'Tech support';

  circle = PlusDomains.Circles.insert(circle, userId);
  Logger.log('Created "Tech support" circle with id: ' + circle.id);
}

Getting a list of a user's posts

The following example demonstrates how to list a user's posts. The returned results contain a brief summary of the posts, including a title. Use the Activities.get() method to read the full details of a post.

advanced/googlePlusDomains.gs
/**
 * The following example demonstrates how to list a user's posts. The returned
 * results contain a brief summary of the posts, including a title. Use the
 * Activities.get() method to read the full details of a post.
 */
function getPosts() {
  var userId = 'me';
  var pageToken;
  var posts;
  do {
    posts = PlusDomains.Activities.list(userId, 'user', {
      maxResults: 100,
      pageToken: pageToken,
    });
    if (posts.items) {
      for (var i = 0; i < posts.items.length; i++) {
        var post = posts.items[i];
        Logger.log('ID: %s, Content: %s', post.id, post.object.content);
      }
    }
    pageToken = posts.nextPageToken;
  } while (pageToken);
}

Creating a post

The following example demonstrates how to create a post that is available to all users within your G Suite domain.

advanced/googlePlusDomains.gs
/**
 * The following example demonstrates how to create a post that is available
 * to all users within your G Suite domain.
 */
function createPost() {
  var userId = 'me';
  var post = {
    object: {
      originalContent: 'Happy Monday! #caseofthemondays',
    },
    access: {
      items: [{
        type: 'domain',
      }],
      domainRestricted: true,
    },
  };

  post = PlusDomains.Activities.insert(post, userId);
  Logger.log('Post created with URL: %s', post.url);
}

Send feedback about...

Apps Script
Apps Script
Need help? Visit our support page.