2013-10-08 26 views
0

我使用,谷歌日曆.NET API V3域寬代表團

asp.net 4.0中,谷歌日曆API V3並與Windows 2003 R2的Web服務器IIS 6.0的環境,我們有我們自己的行貨谷歌域名

我的應用程序需要訪問很多人的Google日曆,並添加/刪除/更新早些時候我們使用過V2並且正在使用消費者密鑰和消費者密碼的事件。目前我的代碼已經遷移到V3版本,並且正常工作,因爲我使用的是使用API​​密鑰和加密密鑰文件的服務帳戶類型。但我的客戶不太熱衷,他們正在尋找類似於V2 V2的認證OAuth 2.0。

所以我的問題什麼是最好的辦法,而不是服務帳戶與V3執行所有的操作應用於一次性身份驗證,如V2的用戶羣的所有操作?

感謝, MVM

回答

0

您可以使用日曆API V3和Web授權。在這種情況下,網頁將被重定向到用戶許可屏幕,然後最終用戶應授權請求。

using System; 
using System.Threading; 
using System.Threading.Tasks; 

using Google; 
using Google.Apis.Auth.OAuth2; 
using Google.Apis.Calendar.v3; 
using Google.Apis.Calendar.v3.Data; 
using Google.Apis.Services; 

namespace Calendar.Sample 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
       new ClientSecrets 
       { 
        ClientId = "CLIENT_ID_HERE", 
        ClientSecret = "CLIENT_SECRET_HERE", 
       }, 
       new[] { CalendarService.Scope.Calendar }, 
       "user", 
       CancellationToken.None).Result; 

      // Create the service. 
      var service = new CalendarService(new BaseClientService.Initializer() 
      { 
       HttpClientInitializer = credential, 
       ApplicationName = "Calendar API Sample", 
      }); 

      ... 
     } 
    } 
}