コード例 #1
2
	/// <summary>
	/// Auth and get all files in AppData.
	/// </summary>
	IEnumerator InitGoogleDrive()
	{
		initInProgress = true;

		drive = new GoogleDrive();
		drive.ClientID = "897584417662-rnkgkl5tlpnsau7c4oc0g2jp08cpluom.apps.googleusercontent.com";
		drive.ClientSecret = "tGNLbYnrdRO2hdFmwJAo5Fbt";

		var authorization = drive.Authorize();
		yield return StartCoroutine(authorization);

		if (authorization.Current is Exception)
		{
			Debug.LogWarning(authorization.Current as Exception);
			goto finish;
		}
		else
			Debug.Log("User Account: " + drive.UserAccount);

		// Get all files in AppData folder and view text file.
		{
			var listFiles = drive.ListFiles(drive.AppData);
			yield return StartCoroutine(listFiles);
			var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

			if (files != null)
			{
				foreach (var file in files)
				{
					Debug.Log(file);

					if (file.Title.EndsWith(".txt"))
					{
						var download = drive.DownloadFile(file);
						yield return StartCoroutine(download);
						
						var data = GoogleDrive.GetResult<byte[]>(download);
						Debug.Log(System.Text.Encoding.UTF8.GetString(data));
					}
				}
			}
			else
			{
				Debug.LogError(listFiles.Current);
			}
		}

	finish:
		initInProgress = false;
	}
コード例 #2
0
        public IHttpActionResult AuthorizeDrive([FromUri] string code, [FromUri] string state)
        {
            var url = RedirectUrl;

            try
            {
                var connector = new GoogleDrive(DataRepository);

                var member   = GetMemberFromAuthenticatedUser();
                var memberId = member.Id;

                var isAuthorized = connector.Authorize(code, memberId, Request.RequestUri.ToString());

                if (isAuthorized && member.StorageAccessType == StorageProviderType.None)
                {
                    member.StorageAccessType = StorageProviderType.GoogleDrive;
                    DataRepository.Update(member);
                }
                connector.RefreshFolderContent();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(BadRequest("Cannot authorize"));
            }
            return(Redirect(url));
        }
コード例 #3
0
    /// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "897584417662-rnkgkl5tlpnsau7c4oc0g2jp08cpluom.apps.googleusercontent.com";
        drive.ClientSecret = "tGNLbYnrdRO2hdFmwJAo5Fbt";

        drive.Scopes = new string[] {
            "https://www.googleapis.com/auth/drive.file",
            "https://www.googleapis.com/auth/userinfo.email",
            "https://www.googleapis.com/auth/drive.appdata",
        };

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            var listFiles = drive.ListFiles(drive.AppData);
            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]>(download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
コード例 #4
0
ファイル: DriveTest.cs プロジェクト: byunghwl/VR_Rehearsal
    /// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "251952116687-bl6cbb0n9veq5ovirpk5n99pjlgtf16g.apps.googleusercontent.com";
        drive.ClientSecret = "z65O11Za6aB74a7r21_TbtFL";

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            //var listFiles = drive.ListFiles(drive.AppData);
            //var listFiles = drive.ListAllFiles();
            var listFiles = drive.ListFolders("");


            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]>(download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
コード例 #5
0
ファイル: DriveTest.cs プロジェクト: MangoSister/VR_Rehearsal
	/// <summary>
	/// Auth and get all files in AppData.
	/// </summary>
	IEnumerator InitGoogleDrive()
	{
		initInProgress = true;

		drive = new GoogleDrive();
		drive.ClientID = "251952116687-bl6cbb0n9veq5ovirpk5n99pjlgtf16g.apps.googleusercontent.com";
		drive.ClientSecret = "z65O11Za6aB74a7r21_TbtFL";

		var authorization = drive.Authorize();
		yield return StartCoroutine(authorization);

		if (authorization.Current is Exception)
		{
			Debug.LogWarning(authorization.Current as Exception);
			goto finish;
		}
		else
			Debug.Log("User Account: " + drive.UserAccount);

		// Get all files in AppData folder and view text file.
		{
			//var listFiles = drive.ListFiles(drive.AppData);
			//var listFiles = drive.ListAllFiles();
			var listFiles = drive.ListFolders("");


			yield return StartCoroutine(listFiles);
			var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

			if (files != null)
			{
				foreach (var file in files)
				{
					Debug.Log(file);

					if (file.Title.EndsWith(".txt"))
					{
						var download = drive.DownloadFile(file);
						yield return StartCoroutine(download);
						
						var data = GoogleDrive.GetResult<byte[]>(download);
						Debug.Log(System.Text.Encoding.UTF8.GetString(data));
					}
				}
			}
			else
			{
				Debug.LogError(listFiles.Current);
			}
		}

	finish:
		initInProgress = false;
	}
コード例 #6
0
    /// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "327028157545-te6a8nm4josmi80t08i3mvkn3snmnt9m.apps.googleusercontent.com";
        drive.ClientSecret = "XJWfBPzJinRvj1JLytI-eyWK";

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            var listFiles = drive.ListFiles(drive.AppData);
            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> > (listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]> (download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
コード例 #7
0
    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);
        }
    }
コード例 #8
0
    IEnumerator StartAuthentication_internal(boolFuncResult callback, int trialNumber)
    {
        _initInProgress = true;

        _drive              = new GoogleDrive();
        _drive.ClientID     = "251952116687-o29juik9i0qbl6ktpa0n97cavk8cvip4.apps.googleusercontent.com";
        _drive.ClientSecret = "0ZptNq9TwzL7enTtlRUOoZ3_";

        var authorization = _drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
                        #if UNITY_EDITOR
                        #endif
            Exception temp = (authorization.Current as Exception);
            string    res  = temp.ToString();

            if (res == "GoogleDrive+Exception: Invalid credential.")
            {
                callback(true, 1);
            }
            else
            {
                callback(false, 0);
            }
        }
        else
        {
                        #if UNITY_EDITOR
            Debug.Log("User Account: " + _drive.UserAccount);
                        #endif
            callback(true, 0);
        }

        _initInProgress = false;
    }
コード例 #9
0
	IEnumerator StartAuthentication_internal(boolFuncResult callback ,int trialNumber){
		_initInProgress = true;

		_drive = new GoogleDrive();
		_drive.ClientID = "251952116687-o29juik9i0qbl6ktpa0n97cavk8cvip4.apps.googleusercontent.com";
		_drive.ClientSecret = "0ZptNq9TwzL7enTtlRUOoZ3_";

		var authorization = _drive.Authorize();
		yield return StartCoroutine(authorization);

		if (authorization.Current is Exception) {
			
			#if UNITY_EDITOR
			#endif
			Exception temp =(authorization.Current as Exception);
			string res = temp.ToString();
		
			if(res == "GoogleDrive+Exception: Invalid credential."){
					callback (true, 1);
				
			}else{
				callback (false,0);
			}
				
		}else {
			#if UNITY_EDITOR
			Debug.Log("User Account: " + _drive.UserAccount);	
			#endif
			callback (true,0);
		}
			
		_initInProgress = false;
	}