2013-11-14 134 views
4

使用此代碼時在我的Visual Stuidio Win窗體項目中。NativeApplicationClient不受任何支持

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret); 

我得到一個消息

NativeApplicationClient不支持任何更多,它會在1.7.0-β被刪除。請考慮使用支持.NET 4的新Google.Apis.Auth NuGet包,.NET的Windows Store應用程序的Windows Phone 7.5和8和便攜式類庫以及

我使用

安裝包Google.Apis.Authentication -pre

如果我添加Google.apis.auth代替Google.Apis.Authentication它不apeare甚至有NativeApplicationClient。但是我無法找到任何關於NativeApplicationClient所使用的內容的信息。

回答

3

是的,我得到它的工作。

在項目中安裝這些軟件包

pm> install-package google.apis -pre 
pm> install-package google.apis.drive.v2 -pre 

添加這些usings

using Google.Apis.Auth.OAuth2; 
using Google.Apis.Services; 
using System.IO; 
using Google.Apis.Drive.v2; 
using Google.Apis.Util.Store; 
using System.Threading; 

private void Form1_Load(object sender, EventArgs e) 
{ 
UserCredential credential; 
using (var stream = new FileStream("client_secrets.json", FileMode.Open, 
           FileAccess.Read)) { 
    GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store"; 
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets, 
    new[] { DriveService.Scope.Drive, 
      DriveService.Scope.DriveFile }, 
    "user", 
    CancellationToken.None, 
    new FileDataStore("Drive.Auth.Store")).Result; 
    } 

}

對於谷歌驅動器,然後我將創建一個驅動器服務。您發送所有對該服務的呼叫。對谷歌分析工作相同。

BaseClientService service = new DriveService(new BaseClientService.Initializer() 
{ 
HttpClientInitializer = credential, 
ApplicationName = "Drive API Sample", 
}); 

我expain這一切在一篇博客文章:http://daimto.com/google-oauth2-csharp/

如果figuer如何給它一個存儲refrshToken和使用,讓我知道我還在努力figuer了這一點。

+0

我可以知道GoogleWebAuthorizationBroker.Folder =「Tasks.Auth.Store」的用法是什麼? – superhuman1314

+0

如果你刪除filedatastore GoogleWebAuthorizationBroker.Folder會告訴它在哪裏存儲認證。你在技術上不需要兩個。 – DaImTo

+0

這是一個較新的教程,它可以更好地解釋它,然後http://www.daimto.com/google-net-filedatastore-demystified/ – DaImTo