コード例 #1
0
        public static void Retrieve()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "1qAnB3vcKDsSuwFmRB0gtDyepFx60t1CdI9hbKAvCXQc";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE
            Document doc = request.Execute();

            fileUtil.createFile(doc);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);
        }
コード例 #3
0
        private void Write()
        {
            string[] Scopes = { DocsService.Scope.Documents, DocsService.Scope.DriveFile, DocsService.Scope.Drive };

            UserCredential credential;

            using (var stream = new FileStream($"/Users/mathiasgammelgaard/credentials/credentials.json", FileMode.Open, FileAccess.Read)) {
                string credPath = "/Users/mathiasgammelgaard/credentials/token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            DocsService service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

            // Define request parameters.
            String documentId = "1tldY_DpX5IM9wPqIKN9FVgwfBT2Ueq__F8pwOI8dLVI";

            DocumentsResource.GetRequest documentRequest = service.Documents.Get(documentId);
            Document doc = documentRequest.Execute();

            List <Request> requests = new List <Request>();

            DeleteAllContent(requests, doc, service, documentId);

            foreach (Course course in courses)
            {
                //AddHeaderLine(course.title, requests, 1);
                foreach (Section section in course.sections)
                {
                    if (section.description != null)
                    {
                        AddHeaderLine(section.name, requests, 3);
                        AddParagraph(section.description.levels[0].description, requests);
                    }
                    else
                    {
                        AddHeaderLine(section.name, requests, 3, false);
                        AddQuizQuestions(section.quiz.levels[0], requests);
                    }
                }
            }



            BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest();

            body.Requests = requests;
            DocumentsResource.BatchUpdateRequest updateRequest = service.Documents.BatchUpdate(body, documentId);

            updateRequest.Execute();
        }
コード例 #4
0
ファイル: GDocApi.cs プロジェクト: piotr-zysk/GAPI
        public Document GetDoc(string fileId)
        {
            DocumentsResource.GetRequest request = this.service.Documents.Get(fileId);
            Document doc = request.Execute();

            return(doc);
        }
コード例 #5
0
        public static string GetTitle(string documentId)
        {
            DocumentsResource.GetRequest request = Service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);
            return(doc.Title);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: FlydisoftTech/KeyboardHook
        private void btn_start_Click(object sender, EventArgs e)
        {
            string[]       Scopes          = { DocsService.Scope.DocumentsReadonly };
            string         ApplicationName = "SmartSV";
            UserCredential credential;

/*            using (var stream =
 *              new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
 *          {
 *              string credPath = "token.json";
 *
 *              credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
 *                  GoogleClientSecrets.Load(stream).Secrets,
 *                  Scopes,
 *                  "user",
 *                  CancellationToken.None,
 *                  new FileDataStore(credPath, true)).Result;
 *              Console.WriteLine("Credential file saved to: " + credPath);
 *          }*/

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = null,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "1PT8NkFir3y74tbbPK1qNIjmw3xtzh39Cet8eaKpqyXU";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);


            // Note: for the application hook, use the Hook.AppEvents() instead
            m_GlobalHook = Hook.GlobalEvents();

            m_GlobalHook.KeyPress += GlobalHookKeyPress;
        }
コード例 #7
0
 public static Document GetDocument(string documentId)
 {
     // Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + " start");
     // Console.WriteLine($"documentId:{documentId}");
     try
     {
         DocumentsResource.GetRequest request = Service.Documents.Get(documentId);
         // Console.WriteLine(request.PrettyPrint);
         Document doc = request.Execute();
         // Console.WriteLine("Found {0}", doc.Title);
         return(doc);
     }
     catch (Google.GoogleApiException ex)
     {
         Console.Error.WriteLine("Googleドキュメントが取得できませんでした。MymeTypeを確認してください。");
         Console.Error.WriteLine($"{ex.GetType().Name} {ex.Message} ");
         throw ex;
     }
 }
コード例 #8
0
        static void Main(string[] args)
        {
            try
            {
                UserCredential credential;
                // Load client secrets.
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    /* The file token.json stores the user's access and refresh tokens, and is created
                     * automatically when the authorization flow completes for the first time. */
                    string credPath = "token.json";

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Google Docs API service.
                var service = new DocsService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });

                // Define request parameters.
                String documentId = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";
                DocumentsResource.GetRequest request = service.Documents.Get(documentId);

                // Prints the title of the requested doc:
                // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
                Document doc = request.Execute();
                Console.WriteLine("The title of the doc is: {0}", doc.Title);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #9
0
        public static string GetAllText(string documentId)
        {
            Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + " start");
            DocumentsResource.GetRequest request = Service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);

            var bodyText = string.Empty;

            foreach (var element in doc.Body.Content)
            {
                bodyText += GetContent(element);
            }

            return(bodyText);
        }
コード例 #10
0
        public static List <string> ReadRules()
        {
            DocsService service = LogintoDocs();

            DocumentsResource.GetRequest request = service.Documents.Get(docsId);
            Document      doc     = request.Execute();
            List <string> message = new List <string>();

            foreach (var text in doc.Body.Content)
            {
                try
                {
                    foreach (var par in text.Paragraph.Elements)
                    {
                        message.Add(par.TextRun.Content);
                    }
                }
                catch { }
            }

            return(message);
        }
コード例 #11
0
ファイル: DocsStartup.cs プロジェクト: SGmuwa/InWords
        public static string Invoke()
        {
            UserCredential credential;

            using (var stream = new FileStream(CRED_FILE, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(TOKEN_FILE, true)).Result;
                Console.WriteLine("Credential file saved to: " + TOKEN_FILE);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = APPLICATION_NAME
            });

            // Define request parameters.
            // ReSharper disable once StringLiteralTypo
            const string documentId = "1-SUfBAAJutCcb-bZHEfqGmiOO7Lh4uoSwpnBuDa-v6A";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/1-SUfBAAJutCcb-bZHEfqGmiOO7Lh4uoSwpnBuDa-v6A/edit?usp=sharing
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Body.Content);

            return(ReadStructuralElements(doc.Body.Content));
        }
コード例 #12
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "10iaemvyMan4ZfjUj1VqI1ubPCsh-krpPI92Pm3z5zjs";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Parse the document's body
            Document doc = request.Execute();

            Console.WriteLine($"Title: {doc.Title}");
            var paragraphs = 0;
            var days       = 0;
            var wfh        = 0;
            var tagDict    = new Dictionary <string, int>();

            foreach (var element in doc.Body.Content)
            {
                if (element.Paragraph != null)
                {
                    paragraphs += 1;
                    var sb = new StringBuilder();
                    foreach (var parel in element.Paragraph.Elements)
                    {
                        sb.Append(parel.TextRun?.Content);
                    }
                    var text = sb.ToString();

                    // Date "title" parsing
                    if (IsADateHeading(text))
                    {
                        Console.WriteLine($"Date: {GetDateFromTitle(text.Trim()).ToString("dd/MMM/yyyy")}");
                        days += 1;
                        if (text.ToLower().Contains("[wfh]"))
                        {
                            wfh += 1;
                        }
                        SearchForPossibleDayTags(text, tagDict);
                    }

                    // Pluralsight example
                    if ((text != null) && (text.Contains("Pluralsight:")))
                    {
                        Console.WriteLine(text);
                    }
                }
            }
            Console.WriteLine($"\nParagraph count: {paragraphs}");
            Console.WriteLine($"Work days: {days}");
            Console.WriteLine($"Remoting days: {wfh} ({decimal.Parse(wfh.ToString())/decimal.Parse(days.ToString()):P})");
            Console.WriteLine("\nDay Tags:");
            foreach (var item in tagDict.OrderBy(i => i.Key))
            {
                Console.WriteLine($"[{item.Key}]: {item.Value}");
            }
            Console.ReadLine();
        }