自從2011年11月起,我在ASP.NET應用程序中使用舊版本的Calendar GData API (v1, v2),允許用戶在提交用戶名和密碼後檢索和/或創建日曆活動,直到2014年11月17日之前谷歌決定關閉這個版本的API作爲宣佈Calendar GData API/Google Calendar Connectors deprecation我的Google身份驗證問題
現在我堅持的Google APIS Calendar (v3)的新版本,它迫使我使用認證過程的不同場景代替傳統之一。我完全不介意使用此版本的Calendar API,因爲它支持所有必需的功能,但現在我不知道如何處理多個用戶身份驗證,以便使用其每個用戶代碼控制檯註冊的用戶客戶端ID和祕密。
所以我的問題是:有沒有辦法讓用戶使用他/她的正常憑據登錄(通過用戶名/密碼或Google+ Sign Up功能),並繞過創建API項目,啓用所需的API和通過ASP.net代碼在控制檯內創建新的用戶憑證?
任何在C#ASP.net中製作的示例代碼都非常感謝。
編輯:這是我的驗證碼我用
public static CalendarService Authenticate()
{
CalendarService service;
GoogleAuthorizationCodeFlow flow;
string json_File = System.Configuration.ConfigurationManager.AppSettings["Authentication_Path"];
string store_path = System.Configuration.ConfigurationManager.AppSettings["FileStore_Path"];
string url = System.Configuration.ConfigurationManager.AppSettings["Authent_URL"];
using (var stream = new FileStream(json_File, FileMode.Open, FileAccess.Read))
{
flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
DataStore = new FileDataStore(store_path),
ClientSecretsStream = stream,
Scopes = new[] { CalendarService.Scope.Calendar }
});
}
var uri = url;
var result = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync("TRAININGCALENDAR", CancellationToken.None).Result;
if (result.Credential == null)
{
GoogleCalendar_Bus.Main_Authentication(url, "", "");
}
// The data store contains the user credential, so the user has been already authenticated.
service = new CalendarService(new BaseClientService.Initializer
{
ApplicationName = "Calendar API Sample",
HttpClientInitializer = result.Credential
});
if (result.Credential != null)
{
service = new CalendarService(new BaseClientService.Initializer
{
ApplicationName = "Calendar API Sample",
HttpClientInitializer = result.Credential
});
}
return service;
}
感謝DalmTo提供此信息,但它確實沒有任何意義,因爲Google通過用戶名和密碼關閉了正常的身份驗證過程,迫使每個用戶(甚至是新用戶訪問我的應用程序)創建一個API項目,並且用戶憑證開始使用Calendar API。那就是我的意思 !!!! – 2014-12-08 06:32:21