是的,我得到它的工作。
在項目中安裝這些軟件包
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了這一點。
我可以知道GoogleWebAuthorizationBroker.Folder =「Tasks.Auth.Store」的用法是什麼? – superhuman1314
如果你刪除filedatastore GoogleWebAuthorizationBroker.Folder會告訴它在哪裏存儲認證。你在技術上不需要兩個。 – DaImTo
這是一個較新的教程,它可以更好地解釋它,然後http://www.daimto.com/google-net-filedatastore-demystified/ – DaImTo