Учетная запись службы Google drive
Как просмотреть файлы, загруженные в учетную запись службы Google Drive, из ASP.NET веб-приложение ? Я использовал Google Drive API v3 и предоставил здесь код, который я использовал для загрузки файлов. Пожалуйста, помогите мне в этом. Спасибо!
Что я уже пробовал:
using System; using Google.Apis.Drive.v3; using Google.Apis.Auth.OAuth2; using System.Threading; using Google.Apis.Util.Store; using Google.Apis.Services; using Google.Apis.Drive.v3.Data; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using System.Web.UI; namespace Sample { public partial class testing : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private static string GetMimeType(string fileName) { string mimeType = "application/unknown"; string ext = System.IO.Path.GetExtension(fileName).ToLower(); Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); if (regKey != null && regKey.GetValue("Content Type") != null) mimeType = regKey.GetValue("Content Type").ToString(); return mimeType; } protected void Button2_Click(object sender, EventArgs e) { connect(); } public void connect() { string[] scopes = new string[] { DriveService.Scope.Drive }; // Full access var keyFilePath = @"D:\kk\****46bb0790d147.p12"; // Downloaded from https://console.developers.google.com var serviceAccountEmail = "k******.iam.gserviceaccount.com"; // found https://console.developers.google.com //loading the Key file var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable); var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = scopes }.FromCertificate(certificate)); ///////////////////////// var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Drive API Sample", }); ///////////////////////// if (System.IO.File.Exists(@"C:\Project\Uploads\Eidea.txt")) { File body = new File(); body.Name = System.IO.Path.GetFileName(@"C:\Project\Uploads\Eidea.txt"); body.Description = "File uploaded"; body.MimeType = GetMimeType(@"C:\Project\Uploads\Eidea.txt"); // File's content. byte[] byteArray = System.IO.File.ReadAllBytes(@"C:\Project\Uploads\Eidea.txt"); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); try { FilesResource.CreateMediaUpload request = service.Files.Create(body, stream, GetMimeType(@"C:\Project\Uploads\Eidea.txt")); request.Upload(); // Console.WriteLine(request.ResponseBody); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + request.ResponseBody + "')", true); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } } } } }