public static void FinishAuthenticate(GoogleDataSettings settings)
        {
            try
            {
                OAuth2Parameters parameters = new OAuth2Parameters()
                {
                    ClientId     = settings.OAuth2Data.client_id,
                    ClientSecret = settings.OAuth2Data.client_secret,
                    RedirectUri  = REDIRECT_URI,

                    Scope      = SCOPE,
                    AccessType = "offline",  // IMPORTANT
                    TokenType  = TOKEN_TYPE, // IMPORTANT

                    AccessCode = settings._AccessCode
                };
                OAuthUtil.GetAccessToken(parameters);
                string accessToken  = parameters.AccessToken;
                string refreshToken = parameters.RefreshToken;
                //Debug.Log("OAuth Access Token: " + accessToken + "\n");
                //Debug.Log("OAuth Refresh Token: " + refreshToken + "\n");

                settings._RefreshToken = refreshToken;
                settings._AccessToken  = accessToken;
            }
            catch (Exception e)
            {
                // To display the error message with EditorGUI.Dialogue, we throw it again.
                throw new Exception(e.Message);
            }
        }
        public static GOAuth2RequestFactory RefreshAuthenticate(GoogleDataSettings settings)
        {
            if (string.IsNullOrEmpty(settings._RefreshToken) ||
                string.IsNullOrEmpty(settings._AccessToken))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(settings.OAuth2Data.client_id) ||
                string.IsNullOrEmpty(settings.OAuth2Data.client_id))
            {
                return(null);
            }

            OAuth2Parameters parameters = new OAuth2Parameters()
            {
                RefreshToken = settings._RefreshToken,
                AccessToken  = settings._AccessToken,
                ClientId     = settings.OAuth2Data.client_id,
                ClientSecret = settings.OAuth2Data.client_secret,
                Scope        = "https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds",
                AccessType   = "offline",
                TokenType    = "refresh"
            };

            return(new GOAuth2RequestFactory("spreadsheet", "MySpreadsheetIntegration-v1", parameters));
        }
Example #3
0
    /// <summary>
    /// Create account setting asset file if it does not exist.
    /// </summary>
    public static GoogleDataSettings Create()
    {
        string filePath = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);

        s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath(filePath, typeof(GoogleDataSettings));

        if (s_Instance == null)
        {
            s_Instance = CreateInstance <GoogleDataSettings> ();

            string path = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
            AssetDatabase.CreateAsset(s_Instance, path);

            s_Instance.AssetPath  = Path.GetDirectoryName(path);
            s_Instance.AssetPath += "/";

            // saves file path of the created asset.
            EditorUtility.SetDirty(s_Instance);
            AssetDatabase.SaveAssets();

            EditorUtility.DisplayDialog(
                "Validate Settings",
                "Default google data settings file has been created for accessing Google project page. You should validate these before proceeding.",
                "OK"
                );
        }
        else
        {
            Debug.LogWarning("Already exist at " + filePath);
        }

        Selection.activeObject = s_Instance;

        return(s_Instance);
    }
Example #4
0
    public virtual void OnEnable()
    {
        // resolves TlsException error
        ServicePointManager.ServerCertificateValidationCallback = Validator;

        GoogleDataSettings settings = GoogleDataSettings.Instance;

        if (settings != null)
        {
            if (string.IsNullOrEmpty(settings.OAuth2Data.client_id) ||
                string.IsNullOrEmpty(settings.OAuth2Data.client_secret))
            {
                Debug.LogWarning("Client_ID and Client_Sceret is empty. Reload .json file.");
            }

            if (string.IsNullOrEmpty(settings._AccessCode))
            {
                Debug.LogWarning("AccessCode is empty. Redo authenticate again.");
            }
        }
        else
        {
            Debug.LogError("Failed to get google data settings. See the google data setting if it has correct path.");
            return;
        }

        //database = target as BaseDatabase;
        //Debug.Log ("Target type: " + database.GetType().ToString());
    }
Example #5
0
    public static void loadGoogleSheet <T, D> (T tableAsset) where T : BaseScriptableObject <D> where D : new()
    {
        // resolves TlsException error
        ServicePointManager.ServerCertificateValidationCallback = Validator;

        GoogleDataSettings settings = GoogleDataSettings.Instance;

        if (settings != null)
        {
            if (string.IsNullOrEmpty(settings.OAuth2Data.client_id) ||
                string.IsNullOrEmpty(settings.OAuth2Data.client_secret))
            {
                Debug.LogWarning("Client_ID and Client_Sceret is empty. Reload .json file.");
            }

            if (string.IsNullOrEmpty(settings._AccessCode))
            {
                Debug.LogWarning("AccessCode is empty. Redo authenticate again.");
            }
        }
        else
        {
            Debug.LogError("Failed to get google data settings. See the google data setting if it has correct path.");
            return;
        }

        T      targetData = tableAsset;
        var    client     = new DatabaseClient("", "");
        string error      = string.Empty;
        var    db         = client.GetDatabase(targetData.SheetName, ref error);
        var    table      = db.GetTable <D> (targetData.WorksheetName) ?? db.CreateTable <D> (targetData.WorksheetName);

        List <D> myDataList = new List <D> ();

        var all = table.FindAll();

        foreach (var elem in all)
        {
            D data = new D();

            data = Cloner.DeepCopy <D> (elem.Element);
            myDataList.Add(data);
        }

        targetData.dataArray = myDataList.ToArray();
        EditorUtility.SetDirty(targetData);
        AssetDatabase.SaveAssets();
    }
Example #6
0
        public DatabaseClient(GoogleDataSettings settings)
        {
            GOAuth2RequestFactory requestFactory = GDataDBRequestFactory.RefreshAuthenticate(settings);

            var docService = new DocumentsService("database")
            {
                RequestFactory = requestFactory
            };

            documentService = docService;

            var ssService = new SpreadsheetsService("database")
            {
                RequestFactory = requestFactory
            };

            spreadsheetService = ssService;
        }
Example #7
0
    public static GoogleDataSettings Create()
    {
        s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath(filePath, typeof(GoogleDataSettings));

        if (s_Instance == null)
        {
            s_Instance = CreateInstance <GoogleDataSettings> ();

            AssetDatabase.CreateAsset(s_Instance, filePath);

            Selection.activeObject = s_Instance;

            EditorUtility.DisplayDialog(
                "Validate Settings",
                "Default google dasa settings have been created for accessing Google project page. You should validate these before proceeding.",
                "OK"
                );
        }

        return(s_Instance);
    }
	public static GoogleDataSettings Create()
	{
		s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath (filePath, typeof (GoogleDataSettings));
						
		if (s_Instance == null)
		{
			s_Instance = CreateInstance<GoogleDataSettings> ();

			AssetDatabase.CreateAsset (s_Instance, filePath);

			Selection.activeObject = s_Instance;
			
			EditorUtility.DisplayDialog (
				"Validate Settings",
				"Default google dasa settings have been created for accessing Google project page. You should validate these before proceeding.",
				"OK"
			);
		}
		
		return s_Instance;
	}
Example #9
0
    public virtual void OnEnable()
    {
        // resolves TlsException error
        ServicePointManager.ServerCertificateValidationCallback = Validator;

        GoogleDataSettings settings = GoogleDataSettings.Instance;

        if (settings != null)
        {
            username = settings.Account;
            password = settings.Password;
        }
        else
        {
            Debug.LogError("Failed to get google data settings. See the google data setting if it has correct path.");
            return;
        }

        //database = target as BaseDatabase;
        //Debug.Log ("Target type: " + database.GetType().ToString());
    }
        public static void InitAuthenticate(GoogleDataSettings settings)
        {
            string clientId     = settings.OAuth2Data.client_id;
            string clientSecret = settings.OAuth2Data.client_secret;
            string accessCode   = settings._AccessCode;

            // OAuth2Parameters holds all the parameters related to OAuth 2.0.
            OAuth2Parameters parameters = new OAuth2Parameters
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                RedirectUri  = REDIRECT_URI,
                Scope        = SCOPE,
                AccessType   = "offline",
                TokenType    = TOKEN_TYPE
            };

            // Retrieves the Authorization URL
            // IMPORTANT
            // IMPORTANT

            string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);

            Debug.Log(authorizationUrl);
            //Debug.Log("Please visit the URL above to authorize your OAuth "
            //      + "request token.  Once that is complete, type in your access code to "
            //      + "continue...");

            parameters.AccessCode = accessCode;

            if (IsValidURL(authorizationUrl))
            {
                Application.OpenURL(authorizationUrl);
            }
            else
            {
                Debug.LogError("Invalid URL: " + authorizationUrl);
            }
        }
    /// <summary>
    /// Create account setting asset file if it does not exist.
    /// </summary>
    public static GoogleDataSettings Create()
    {
        string filePath = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
        s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath(filePath, typeof(GoogleDataSettings));

        if (s_Instance == null)
        {
            s_Instance = CreateInstance<GoogleDataSettings> ();

            string path = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
            AssetDatabase.CreateAsset(s_Instance, path);

            s_Instance.AssetPath = Path.GetDirectoryName(path);
            s_Instance.AssetPath += "/";

            // saves file path of the created asset.
            EditorUtility.SetDirty(s_Instance);
            AssetDatabase.SaveAssets();

            EditorUtility.DisplayDialog (
                "Validate Settings",
                "Default google dasa settings have been created for accessing Google project page. You should validate these before proceeding.",
                "OK"
            );
        }
        else
        {
            Debug.LogWarning("Already exist at " + filePath);
        }

        Selection.activeObject = s_Instance;

        return s_Instance;
    }
 /// <summary>
 /// инициализация модели данных
 /// </summary>
 /// <param name="settings"></param>
 public void Init(GoogleDataSettings settings)
 {
     client = new DatabaseClient(settings); //создаем клиента для доступа к гугл диску
 }
 public void OnEnable()
 {
     setting = target as GoogleDataSettings;
 }
	public void OnEnable()
	{
		googleData = target as GoogleDataSettings;
	}
    public void OnEnable()
    {
        setting = target as GoogleDataSettings;

        UnsafeSecurityPolicy.Instate();
    }
    public void OnEnable()
    {
        setting = target as GoogleDataSettings;

        UnsafeSecurityPolicy.Instate();
    }
Example #17
0
 public static void CreateGoogleDataSetting()
 {
     GoogleDataSettings.Create();
 }