2012-10-04 5 views
1

Google Apps 스크립트 및 OAuth 인증을 사용하여 다른 도메인의 다른 사용자와 도메인의 사용자의 Google 캘린더를 공유하려고합니다. 그러나 나는이 일을 수행 할 수 없다. 나는 모든 캘린더 일정을 가져 왔지만 공유는 할 수 없었다. 모든 해결책을 주시면 감사하겠습니다. 당신이 할 수없는 구글 스크립트에서Google Apps Script : 캘린더를 다른 사용자와 공유하는 방법

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는 캘린더 공유를 지원하지 않습니다 (현재). 해결 방법은 스크립트를 사용하고 UrlFetch (OAuth 포함)를 사용하여 Google 캘린더 API https://developers.google.com/google-apps/calendar/v3/reference/을 호출하여 캘린더 ID를 가져 오는 것일 수 있습니다. 인증을 받았는지 확인하고, 스크립트에서 가져온 ID를 기반으로 캘린더를 얻으려면 'get'을 수행하고 ACL을 얻은 다음 도메인 외부의 사용자와 공유 할 새 항목을 추가하십시오.

쉬운 해결책이 아닙니다. 죄송합니다.

+0

캘린더 API를 통해 캘린더 공유가 가능합니다. 나는 내 질문을 대답으로 업데이트했다. 한번보세요. –

0

이 사용자가 단순히이 새 캘린더에 가입하도록 허용하는 앱을 만들면 어떨까요? 필요한 모든 도구는 가스 캘린더 서비스에 있습니다. 다음은 예입니다. such an application

관련 문제