コード例 #1
0
        public static void FinishAuthenticate(GoogleSettings googleSettings)
        {
            try {
                OAuth2Parameters parameters = new OAuth2Parameters();
                parameters.ClientId     = googleSettings.authInfo.client_id;
                parameters.ClientSecret = googleSettings.authInfo.client_secret;
                parameters.RedirectUri  = googleSettings.authInfo.GetRedirectURI();

                parameters.Scope      = SCOPE;
                parameters.AccessType = "offline";  // IMPORTANT
                parameters.TokenType  = TOKEN_TYPE; // IMPORTANT

                parameters.AccessCode = googleSettings.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");

                googleSettings.refreshToken = refreshToken;
                googleSettings.accessToken  = accessToken;
            }
            catch (Exception e) {
                // To display the error message with EditorGUI.Dialogue, we throw it again.
                throw new Exception(e.Message);
            }
        }
コード例 #2
0
        public GoogleDatabaseQuery(GoogleSettings settings)
        {
            var requestFactory = GoogleRequest.RefreshAuthenticate(settings);

            var docService = new DocumentsService("database");

            docService.RequestFactory = requestFactory;

            documentService = docService;

            var ssService = new SpreadsheetsService("database");

            ssService.RequestFactory = requestFactory;
            spreadsheetService       = ssService;
        }
コード例 #3
0
        public static GOAuth2RequestFactory RefreshAuthenticate(GoogleSettings googleSettings)
        {
            if (string.IsNullOrEmpty(googleSettings.refreshToken) ||
                string.IsNullOrEmpty(googleSettings.accessToken) ||
                string.IsNullOrEmpty(googleSettings.authInfo.client_id))
            {
                return(null);
            }

            OAuth2Parameters parameters = new OAuth2Parameters()
            {
                RefreshToken = googleSettings.refreshToken,
                AccessToken  = googleSettings.accessToken,
                ClientId     = googleSettings.authInfo.client_id,
                ClientSecret = googleSettings.authInfo.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));
        }
コード例 #4
0
        public static void InitAuthenticate(GoogleSettings googleSettings)
        {
            string clientId     = googleSettings.authInfo.client_id;
            string clientSecret = googleSettings.authInfo.client_secret;
            string accessCode   = googleSettings.accessCode;

            // OAuth2Parameters holds all the parameters related to OAuth 2.0.
            OAuth2Parameters parameters = new OAuth2Parameters();

            parameters.ClientId     = clientId;
            parameters.ClientSecret = clientSecret;
            parameters.RedirectUri  = googleSettings.authInfo.GetRedirectURI();

            // Retrieves the Authorization URL
            parameters.Scope      = SCOPE;
            parameters.AccessType = "offline";  // IMPORTANT
            parameters.TokenType  = TOKEN_TYPE; // 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);
                const string message = @"Copy the 'Access Code' on your browser into the access code textfield.";
                EditorUtility.DisplayDialog("Info", message, "OK");
            }
            else
            {
                EditorUtility.DisplayDialog("Error", "Invalid URL: " + authorizationUrl, "OK");
            }
        }
コード例 #5
0
 public GoogleParser(GoogleSettings settings, string sheetName)
 {
     mSheetName     = sheetName;
     mDatabaseQuery = new GoogleDatabaseQuery(settings);
 }