是的,我让它工作了。
在你的项目中安装这些包
pm> install-package google.apis -pre
pm> install-package google.apis.drive.v2 -pre
添加这些使用
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",
});
我在一篇博文中解释了这一切:http: //daimto.com/google-oauth2-csharp/
如果您弄清楚如何为它提供存储的 refrshToken 并使用它,请告诉我我仍在尝试解决这个问题。