2014-07-16 78 views
1

我正在嘗試使用我的客戶端ID和客戶端密鑰通過Gmail API對我的網絡應用程序進行身份驗證。 「快速啓動」示例中的驗證位於here,看起來很複雜。但是,步驟4指出:登錄到Gmail API

注意:此示例中的授權流程因示範目的而大大簡化,不應在Web應用程序中使用。有關更多信息,請參見Authorizing your App with Gmail

但提供的鏈接已損壞。有沒有人成功地爲C#中的Gmail API創建了一個簡單的身份驗證?

我主要問這個問題,以便它可以作爲其他人無法找到答案的資源。

+1

我搜索鏈接本身,而谷歌推出了這個網址:https://開發商。 google.com/gmail/api/auth/about-auth希望它有幫助。 –

+0

爲什麼他們將一些例子限制爲Python? :( – muttley91

回答

3

破碎的鏈接應該是: https://developers.google.com/gmail/api/auth/about-auth

對於C#驗證嘗試類似:

// Create OAuth Credential. 
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets 
    { 
     ClientId = "CLIENT_ID", 
     ClientSecret = "CLIENT_SECRET" 
    }, 
    new[] { GmailService.Scope.GmailModify }, 
    "user", 
    CancellationToken.None).Result; 

// Create the service. 
var service = new GmailService(new BaseClientService.Initializer() 
{ 
    HttpClientInitializer = credential, 
    ApplicationName = "Draft Sender", 
}); 

ListDraftsResponse draftsResponse = service.Users.Drafts.List("me").Execute();