2012-10-04 137 views
1

我想与其他用户在其他域使用谷歌应用程序脚本和OAuth授权分享域中的用户的谷歌日历。但我无法执行此任务。我提取了用户的所有日历事件,但无法进行共享。 任何解决方案,将不胜感激。 谢谢这个问题的Google Apps脚本:如何与其他用户共享日历?

解决方案是在这里:

function calenderSharing(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(consumerKey); 
    oAuthConfig.setConsumerSecret(consumerSecret); 
    return {oAuthServiceName:name, oAuthUseToken:"always"}; 
} 
+0

如果你愿意,你可以回答你自己的问题并选择它。这将有助于未来的访问者更轻松地找到答案。 –

回答

0

在谷歌脚本你不能。日历脚本API不支持共享日历(目前)。 您的解决方法可能是使用脚本获取日历ID并使用UrlFetch(使用OAuth)调用Google日历API https://developers.google.com/google-apps/calendar/v3/reference/。确保您进行身份验证,根据您从脚本中检索的ID执行“获取”以获取日历,获取ACL并添加新条目以与域外的用户共享。

不是一个简单的解决方案。抱歉。

+0

日历共享可以通过Calender API进行。我用答案更新了我的问题。看看这个。 –

0

为什么你不制作一个应用程序,让这个用户只需订阅这个新的日历呢? 所有必要的工具都在气体日历服务中 这里是such an application的一个例子

相关问题