G +域API Google Apps脚本公共帖子扫描

时间:2014-05-16 02:27:56

标签: api google-apps-script google-plus

我正在运行一个脚本来扫描我们的域用户G +发布并标记任何公开共享的帖子,然后向最终用户发送一封电子邮件通知,其中包含该帖子的链接。该脚本是由不再与公司合作的其他人编写的。我想更改脚本,以便标记任何没有"domainRestricted";True的帖子。

这是一个扫描帖子的输出,其中包含与"domainRestricted":True相关联的访问类型。此帖子在域内共享。

{
  "description":"Shared privately",
  "domainRestricted":true,
  "kind":"plus#acl"
}

以下是没有domainRestricted访问权限的已扫描帖子的输出示例。此帖子与包含域外用户的Circle共享,基本上是Public。

{
  "description":"Shared privately",
  "kind":"plus#acl"
}

以下是Public作为访问权限的扫描帖子的输出示例。这篇文章是公开明确分享的。

{
  "items":[{"type":"public"}],
  "description":"Public",
  "kind":"plus#acl"
}

我想更改此代码,以扫描任何不包含访问权限"domainRestricted":True的帖子。

function checkPublicPosts( userId ) {    
  var publicPosts = Array();
  var pageToken;

  try {
    do {
      Logger.log( 'Scanning posts by ' + userId );

      // Search for all Google Plus posts by userId
      posts = PlusDomains.Activities.list( userId, 'user', {
        maxResults: 100,
        pageToken: pageToken
      });

      // If posts are found, check to see if they are public
      if( posts.items ) {
        for( var i = 0; i < posts.items.length; i++ ) {
          var post = posts.items[i];

          var public = false;
          if( !post.access.domainRestricted && ( typeof( post.access.items ) != 'undefined' ) ) {
            for( var j = 0; j < post.access.items.length; j++ ) {
              if( post.access.items[j].type = 'public' ) {
                public = true;
                j = post.access.items.length;
              }
            }
          }

          // If a post is public, add it to the list of public posts for userId
          if( public ) publicPosts.push( post );
        }
      }

      // If user has more than 100 posts, continue with the analysis of subsequent batches of 100
      pageToken = posts.nextPageToken;

    } while (pageToken);

  } catch( err ) {
    // The code above sometimes fails for unexpected reasons. We
    // log this error.

    Logger.log( 'Failed on ' + userId + ' with error ' + err );
  }                      
  return publicPosts;
}

任何人都可以帮助我吗?

0 个答案:

没有答案
相关问题