在Google App脚本中共享日历

海狸IV

我正在尝试通过电子表格构建日历,然后与域中的适当人员共享日历。我这样做是作为附加到电子表格的脚本执行的。

到目前为止,我可以阅读正确的单元格并使用事件构建日历,但是我遇到的问题是弄清楚如何与正确的人共享特定的日历。

我四处搜寻并找到了相同的常规代码来手动请求网页以允许访问,但我尝试使用这些访问均无济于事。我是否错过了其他所有人都假设您已完成的步骤?我所做的就是在电子表格上编写脚本,是否需要进行一些设置才能使其正常工作?

如果无法通过脚本编写,那么解决这种问题的最佳方法是什么?使用PHP和cron作业会更好吗?

我共享日历的代码当前为:

function onEdit() {
 calendarSharing('[email protected]', '[email protected]');
};

function calendarSharing(user1,user2){

    var scope = 'https://www.google.com/calendar/feeds/';
    var fetchArgs = googleOAuth_('calenders', scope);
    var rawXml= "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'>"+
      "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/>"+
      "<gAcl:scope type='user' value='"+user2+"'></gAcl:scope>"+
      "<gAcl:role value='http://schemas.google.com/gCal/2005#owner'>  </gAcl:role></entry>"
    fetchArgs.method = 'POST';
    fetchArgs.payload = rawXml
    fetchArgs.contentType = 'application/atom+xml';

    try{
         var url='https://www.google.com/calendar/feeds/'+user1+'/acl/full'        
         var urlFetch=UrlFetchApp.fetch(url,fetchArgs)                         //Giving Permission To personal account as a owner
       }
    catch(err){
        var err1=err.toString()
        var ex='Exception: Request failed for  returned code 302'
        if(ex==err1.split('.')[0]){
              var tempCalenderUrl=[]
              tempCalenderUrl.id = err1.split('<A HREF="')[1];
              tempCalenderUrl.id = tempCalenderUrl.id.split('"')[0];
              var url=tempCalenderUrl.id
              try{
                  var urlFetch=UrlFetchApp.fetch(url,fetchArgs)   
                 }
              catch(err){}
         }         
     }
}

function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setConsumerKey('anonymous');
  oAuthConfig.setConsumerSecret('anonymous');
  return {oAuthServiceName:name, oAuthUseToken:"always"};
}
莫格斯达

您可以使用“高级日历服务”读取和写入日历共享信息

该实用程序功能将在您具有writer特权的任何日历上插入或更新给定用户的共享权限例如:

// Add user as reader
var rule = shareCalendar( '[email protected]',
                          '[email protected]');

代码

此功能也可以作为要点的一部分使用

/**
 * Set up calendar sharing for a single user. Refer to 
 * https://developers.google.com/google-apps/calendar/v3/reference/acl/insert.
 *
 * @param {string} calId   Calendar ID
 * @param {string} user    Email address to share with
 * @param {string} role    Optional permissions, default = "reader":
 *                         "none, "freeBusyReader", "reader", "writer", "owner"
 *
 * @returns {aclResource}  See https://developers.google.com/google-apps/calendar/v3/reference/acl#resource
 */
function shareCalendar( calId, user, role ) {
  role = role || "reader";

  var acl = null;

  // Check whether there is already a rule for this user
  try {
    var acl = Calendar.Acl.get(calId, "user:"+user);
  }
  catch (e) {
    // no existing acl record for this user - as expected. Carry on.
  }

  if (!acl) {
    // No existing rule - insert one.
    acl = {
      "scope": {
        "type": "user",
        "value": user
      },
      "role": role
    };
    var newRule = Calendar.Acl.insert(acl, calId);
  }
  else {
    // There was a rule for this user - update it.
    acl.role = role;
    newRule = Calendar.Acl.update(acl, calId, acl.id)
  }

  return newRule;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

获取域中共享的所有Google日历

来自分类Dev

获取域中共享的所有Google日历

来自分类Dev

使用Google App脚本更改Google表格共享设置

来自分类Dev

Google日历脚本:删除重复

来自分类Dev

通过API共享私人Google日历

来自分类Dev

Google Calendar API不返回共享日历

来自分类Dev

从Android应用程序中共享Google Plus

来自分类Dev

如何在 Google Cloud Storage 中共享存储分区

来自分类Dev

使用脚本共享Google表格

来自分类Dev

与其他用户共享Google App脚本-请求权限和授权脚本

来自分类Dev

Julia在脚本中共享变量

来自分类Dev

Google日历的Google脚本中日期和时间的格式

来自分类Dev

在 Google App Maker 中创建日历事件

来自分类Dev

分析Google App脚本的性能

来自分类Dev

google app脚本gmail测试

来自分类Dev

从PHP调用Google App脚本?

来自分类Dev

如何在Windows 7中查看Outlook(交换)日历和Google共享日历?

来自分类Dev

无法使用脚本删除我的Google日历中的事件

来自分类Dev

从Google表格脚本到日历的粗体描述文本

来自分类Dev

google apps脚本日历授权必填循环

来自分类Dev

Google Apps脚本日历说明-换行符

来自分类Dev

“找不到脚本功能”-Google App脚本

来自分类Dev

使用Drive API(v2,Ruby Client,Rails,iOS)在多个用户的Google Drive中共享Google文档

来自分类Dev

Google Apps脚本-如何使用高级日历服务过滤多个属性上的日历事件

来自分类Dev

ZEND框架Google日历关闭-PHP Web App

来自分类Dev

Google脚本将日历事件从一个日历移动到另一个日历?

来自分类Dev

通过Google Apps脚本将日历邀请发送到非Google帐户

来自分类Dev

从Google日历到Google表格,脚本无法正确提取时间

来自分类Dev

如何使用Google Apps脚本使用给定的Meet URL创建/更改Google日历活动?

Related 相关文章

  1. 1

    获取域中共享的所有Google日历

  2. 2

    获取域中共享的所有Google日历

  3. 3

    使用Google App脚本更改Google表格共享设置

  4. 4

    Google日历脚本:删除重复

  5. 5

    通过API共享私人Google日历

  6. 6

    Google Calendar API不返回共享日历

  7. 7

    从Android应用程序中共享Google Plus

  8. 8

    如何在 Google Cloud Storage 中共享存储分区

  9. 9

    使用脚本共享Google表格

  10. 10

    与其他用户共享Google App脚本-请求权限和授权脚本

  11. 11

    Julia在脚本中共享变量

  12. 12

    Google日历的Google脚本中日期和时间的格式

  13. 13

    在 Google App Maker 中创建日历事件

  14. 14

    分析Google App脚本的性能

  15. 15

    google app脚本gmail测试

  16. 16

    从PHP调用Google App脚本?

  17. 17

    如何在Windows 7中查看Outlook(交换)日历和Google共享日历?

  18. 18

    无法使用脚本删除我的Google日历中的事件

  19. 19

    从Google表格脚本到日历的粗体描述文本

  20. 20

    google apps脚本日历授权必填循环

  21. 21

    Google Apps脚本日历说明-换行符

  22. 22

    “找不到脚本功能”-Google App脚本

  23. 23

    使用Drive API(v2,Ruby Client,Rails,iOS)在多个用户的Google Drive中共享Google文档

  24. 24

    Google Apps脚本-如何使用高级日历服务过滤多个属性上的日历事件

  25. 25

    ZEND框架Google日历关闭-PHP Web App

  26. 26

    Google脚本将日历事件从一个日历移动到另一个日历?

  27. 27

    通过Google Apps脚本将日历邀请发送到非Google帐户

  28. 28

    从Google日历到Google表格,脚本无法正确提取时间

  29. 29

    如何使用Google Apps脚本使用给定的Meet URL创建/更改Google日历活动?

热门标签

归档