Author Topic: Google Drive question  (Read 2247 times)

mcvpjd3

  • Newbie
  • *
  • Posts: 42
Google Drive question
« on: September 12, 2014, 04:06:39 am »
Just a quick question that popped into my head. I haven't looked into this and not even planning to use it, but just curious about it.

Can winbatch be used to update a document in Google drive? (for example put data into a Google sheet)?

Thanks

stanl

  • Pundit
  • *****
  • Posts: 999
Re: Google Drive question
« Reply #1 on: September 12, 2014, 06:03:16 am »
Google provides C# code (see below) to access the drive. Doubt this can be converted to WB, and it would take more of a C# expert to determine if the WB CLR could work with it
 
Code: [Select]
using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Util;
using Google.Apis.Services;
namespace GoogleDriveSamples
{
    Class DriveCommandLineSample
    {
        static void Main(string[] args)
        {
            String CLIENT_ID = "YOUR_CLIENT_ID";
            String CLIENT_SECRET = "YOUR_CLIENT_SECRET";
            // Register the authenticator and create the service
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
            var service = new DriveService(new BaseClientService.Initializer()
            {
                Authenticator = auth
            });
            File body = new File();
            body.Title = "My document";
            body.Description = "A test document";
            body.MimeType = "text/plain";
            byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
            FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
            request.Upload();
            File file = request.ResponseBody;
            Console.WriteLine("File id: " + file.Id);
            Console.WriteLine("Press Enter to end this process.");
            Console.ReadLine();
        }
        private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
        {
            // Get the auth URL:
            IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            Uri authUri = arg.RequestUserAuthorization(state);
            // Request authorization from the user (by opening a browser window):
            Process.Start(authUri.ToString());
            Console.Write("  Authorization Code: ");
            string authCode = Console.ReadLine();
            Console.WriteLine();
            // Retrieve the access token by using the authorization code:
            return arg.ProcessUserAuthorization(authCode, state);
        }
    }
}
 

td

  • Tech Support
  • *****
  • Posts: 3210
    • WinBatch
Re: Google Drive question
« Reply #2 on: September 12, 2014, 02:26:32 pm »
Google provides a dotNet API for Google Sheet, as well. Since I have never used it nor spent much time even looking it, I can't say how much of it could be used with WinBatch CLR hosting.  Guess would be that it would work as long as you don't do anything that requires delegates for event handling.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade