2014-11-20 4 views
0

며칠 전에 가치가 떨어지는 V2 API에 기반하여 작성된 여러 사용자의 Google 캘린더를 관리하는 .NET 시스템에 모듈이 있습니다.Google 캘린더 - 여러 사용자를 관리하려면 캘린더

제 질문은 어떻게 여러 사용자의 캘린더에 액세스하고 관리 할 수 ​​있습니까? V2 API 에서처럼 우리는 리소스에 액세스하기 위해 사용자 ID와 비밀번호를 전달할 수 있습니다. 그러나 V3에서는 OAuth2가 사용됩니다. 한 번에 한 사용자에 대해 인증을 관리합니다. 어떻게하면 다른 사용자의 캘린더에 액세스 할 수 있습니까? (예 : 사용자 1을 로그인하고 사용자 2를 다시 로그인 하시겠습니까?). 지금까지 관련 예제를 찾을 수 없습니다.

Sub Main() 
    Dim secret As New ClientSecrets 
    secret.ClientId = "MyClientID.apps.googleusercontent.com" 
    secret.ClientSecret = "MyClientSecret" 

    Dim init As New Flows.AuthorizationCodeFlow.Initializer("https://accounts.google.com/o/oauth2/auth", "https://accounts.google.com/o/oauth2/token") 
    init.ClientSecrets = secret 

    Dim flow As New Flows.AuthorizationCodeFlow(init) 
    Dim token As Responses.TokenResponse = flow.LoadTokenAsync("[email protected]", CancellationToken.None).Result 
    Dim credential As New UserCredential(flow, "[email protected]", token) 

    Try 
     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secret, {CalendarService.Scope.Calendar}, "user", CancellationToken.None, New FileDataStore("CAS.GoogleConnector")).Result 
    Catch ex As Exception 
     MsgBox(ex.Message) 
    End Try 

    ' Create the calendar service using an initializer instance 
    Dim initializer As New BaseClientService.Initializer() 
    initializer.HttpClientInitializer = credential 
    initializer.ApplicationName = "Clinic Assist" 
    Dim service As CalendarService 
    service = New CalendarService(initializer) 
    Dim a As CalendarsResource.GetRequest = service.Calendars.Get("[email protected]") 
    a.Execute() 
    Console.WriteLine("Press any key to continue...") 
    Dim key As ConsoleKeyInfo = Console.ReadKey 
    If key.Key = ConsoleKey.N Then 
     NewEvent(service) 
    ElseIf key.Key = ConsoleKey.D Then 
     DeleteEvent(service) 
    ElseIf key.Key = ConsoleKey.C Then 
     NewCalendar(service) 
    End If 
End Sub 

Private Sub NewEvent(service As CalendarService) 

    Dim startDateTime, endDateTime As New Data.EventDateTime 
    startDateTime.DateTime = "2014-12-01T16:00:00" 
    endDateTime.DateTime = "2014-12-01T17:00:00" 

    Dim eventData As New Data.Event 
    With eventData 
     .Start = startDateTime 
     .End = endDateTime 
     .Location = "ALocation" 
     .Summary = "TRY" 
    End With 
    Try 
     Dim insertRequest As InsertRequest = service.Events.Insert(eventData, "[email protected]") 
     insertRequest.Execute() 
    Catch ex As Exception 
     MsgBox(ex.Message) 
    End Try 
End Sub 

내가 " [email protected]을"까지 사용자 ID를 변경하려고 " [email protected]는"그것은뿐만 아니라 USER1 달력에 액세스 할 것으로 보인다. 누군가가 이것을 도울 수 있다면 감사하게 생각하십시오.

답변

0

모든 사용자가 단일 도메인에있는 경우 Service Accounts을 사용할 수 있습니다. 서비스 계정은 개별 최종 사용자 대신 응용 프로그램에 속합니다. 애플리케이션이 서비스 계정을 대신하여 Google API를 호출하므로 사용자가 직접 참여하지 않습니다.

사용자가 동일한 도메인에 있지 않은 경우 응용 프로그램의 각 사용자에 대한 자격 증명을 저장해야합니다. 다음은 link입니다.