IEnumerator ListPresentationsCoroutine() { Drive.ClientID = "327028157545-te6a8nm4josmi80t08i3mvkn3snmnt9m.apps.googleusercontent.com"; Drive.ClientSecret = "XJWfBPzJinRvj1JLytI-eyWK"; // Request authorization. var authorization = Drive.Authorize(); yield return(StartCoroutine(authorization)); if (authorization.Current is Exception) { Debug.LogWarning(authorization.Current as Exception); yield break; } // Authorization succeeded. Debug.Log("User Account: " + Drive.UserAccount); var listFiles = Drive.ListFilesByQueary("mimeType = 'application/vnd.google-apps.presentation'"); //var listFiles = Drive.ListAllFiles (); yield return(StartCoroutine(listFiles)); var files = GoogleDrive.GetResult <List <GoogleDrive.File> > (listFiles); if (files != null && files.Count > 0) { foreach (GoogleDrive.File file in files) { //Debug.Log (file.Title); } GoogleDrive.File file0 = files [0]; var pdfExportLink = file0.ExportLinks ["application/pdf"]; var download = Drive.DownloadFile((string)pdfExportLink); yield return(StartCoroutine(download)); var data = GoogleDrive.GetResult <byte[]> (download); if (data != null) { Debug.Log("Happy"); Stream pdfStream = new MemoryStream(data); //PdfSharp.Pdf.PdfDocument pdfDoc = PdfSharp.Pdf.IO.PdfReader.Open (pdfStream, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import); // Debug.Log (pdfDoc.Info.Title); } } else { Debug.Log("files: " + files.Count); } }
/// <summary> /// Upload a screenshot to the root folder. /// </summary> IEnumerator UploadScreenshot() { if (drive == null || !drive.IsAuthorized || uploadScreenshotInProgress) { yield break; } uploadScreenshotInProgress = true; yield return(new WaitForEndOfFrame()); var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); tex.Apply(); var png = tex.EncodeToPNG(); GameObject.Destroy(tex); tex = null; if (file == null) { var upload = drive.UploadFile("my_screen.png", "image/png", png); yield return(StartCoroutine(upload)); file = GoogleDrive.GetResult <GoogleDrive.File>(upload); } else { var upload = drive.UploadFile(file, png); yield return(StartCoroutine(upload)); file = GoogleDrive.GetResult <GoogleDrive.File>(upload); } uploadScreenshotInProgress = false; }
/// <summary> /// <para>Update 'my_text.txt' in the root folder.</para> /// <para>The file has json data.</para> /// </summary> IEnumerator UploadText() { if (drive == null || !drive.IsAuthorized || uploadTextInProgress) yield break; uploadTextInProgress = true; // Get 'my_text.txt'. var list = drive.ListFilesByQueary("title = 'my_text.txt'"); yield return StartCoroutine(list); GoogleDrive.File file; Dictionary<string, object> data; var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(list); if (files == null || files.Count > 0) { // Found! file = files[0]; // Download file data. var download = drive.DownloadFile(file); yield return StartCoroutine(download); var bytes = GoogleDrive.GetResult<byte[]>(download); try { // Data is json format. var reader = new JsonFx.Json.JsonReader(Encoding.UTF8.GetString(bytes)); data = reader.Deserialize<Dictionary<string, object>>(); } catch (Exception e) { Debug.LogWarning(e); data = new Dictionary<string, object>(); } } else { // Make a new file. file = new GoogleDrive.File(new Dictionary<string, object> { { "title", "my_text.txt" }, { "mimeType", "text/plain" }, { "description", "test" } }); data = new Dictionary<string, object>(); } // Update file data. data["date"] = DateTime.Now.ToString(); if (data.ContainsKey("count")) data["count"] = (int)data["count"] + 1; else data["count"] = 0; // And uploading... { var bytes = Encoding.UTF8.GetBytes(JsonFx.Json.JsonWriter.Serialize(data)); var upload = drive.UploadFile(file, bytes); yield return StartCoroutine(upload); if (!(upload.Current is Exception)) { Debug.Log("Upload complete!"); } } uploadTextInProgress = false; }
/// <summary> /// Upload a screenshot to the root folder. /// </summary> IEnumerator UploadScreenshot() { if (drive == null || !drive.IsAuthorized || uploadScreenshotInProgress) yield break; uploadScreenshotInProgress = true; yield return new WaitForEndOfFrame(); var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); tex.Apply(); var png = tex.EncodeToPNG(); GameObject.Destroy(tex); tex = null; if (file == null) { var upload = drive.UploadFile("my_screen.png", "image/png", png); yield return StartCoroutine(upload); file = GoogleDrive.GetResult<GoogleDrive.File>(upload); } else { var upload = drive.UploadFile(file, png); yield return StartCoroutine(upload); file = GoogleDrive.GetResult<GoogleDrive.File>(upload); } uploadScreenshotInProgress = false; }
/// <summary> /// <para>Update 'my_text.txt' in the root folder.</para> /// <para>The file has json data.</para> /// </summary> IEnumerator UploadText() { if (drive == null || !drive.IsAuthorized || uploadTextInProgress) { yield break; } uploadTextInProgress = true; // Get 'my_text.txt'. var list = drive.ListFilesByQueary("title = 'my_text.txt'"); yield return(StartCoroutine(list)); GoogleDrive.File file; Dictionary <string, object> data; var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(list); if (files == null || files.Count > 0) { // Found! file = files[0]; // Download file data. var download = drive.DownloadFile(file); yield return(StartCoroutine(download)); var bytes = GoogleDrive.GetResult <byte[]>(download); try { // Data is json format. var reader = new JsonFx.Json.JsonReader(Encoding.UTF8.GetString(bytes)); data = reader.Deserialize <Dictionary <string, object> >(); } catch (Exception e) { Debug.LogWarning(e); data = new Dictionary <string, object>(); } } else { // Make a new file. file = new GoogleDrive.File(new Dictionary <string, object> { { "title", "my_text.txt" }, { "mimeType", "text/plain" }, { "description", "test" } }); data = new Dictionary <string, object>(); } // Update file data. data["date"] = DateTime.Now.ToString(); if (data.ContainsKey("count")) { data["count"] = (int)data["count"] + 1; } else { data["count"] = 0; } // And uploading... { var bytes = Encoding.UTF8.GetBytes(JsonFx.Json.JsonWriter.Serialize(data)); var upload = drive.UploadFile(file, bytes); yield return(StartCoroutine(upload)); if (!(upload.Current is Exception)) { Debug.Log("Upload complete!"); } } uploadTextInProgress = false; }