private static GoogleCloudPrintApi.Models.Token GenerateAndSaveToken()
        {
            var token2 = System.IO.File.ReadAllText(TokenPath);

            if (token2 == "")
            {
                var url = provider.BuildAuthorizationUrl("http://127.0.0.1");

                var process = Process.Start("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", url);

                var token = provider.GenerateRefreshTokenAsync("4/h0LryklYY1ByxehWfgjZYyHGO1X_Y5vzFC18yoATZ-0", "http://127.0.0.1").Result;
                SaveToken(token);
            }

            dynamic token3 = JsonConvert.DeserializeObject(token2);

            DateTime dataExpiracao = token3.expire_datetime;

            if (DateTime.Now > dataExpiracao)
            {
                var token = provider.GenerateAccessTokenAsync((string)token3.refresh_token).Result;
                SaveToken(token);
            }
            else
            {
                token = new GoogleCloudPrintApi.Models.Token((string)token3.access_token,
                                                             (string)token3.token_type,
                                                             (long)token3.expires_in,
                                                             (string)token3.refresh_token,
                                                             (DateTime?)token3.expire_datetime);
            }

            return(token);
        }
        /// <summary>
        /// Generates the refresh token. Should be called manually before testing.
        /// </summary>
        public void GenerateRefreshToken()
        {
            var pathMap = new Dictionary <OSPlatform, string>
            {
                { OSPlatform.Windows, "chrome.exe" },
                { OSPlatform.OSX, "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" },
                { OSPlatform.Linux, "/usr/bin/google-chrome" }
            };

            var url     = OAuth2Provider.BuildAuthorizationUrl("http://127.0.0.1");
            var path    = pathMap[pathMap.First(p => RuntimeInformation.IsOSPlatform(p.Key)).Key];
            var process = Process.Start(path, url);

            Console.Write("Please paste the authorization code to continue: ");
            var authCode = Console.ReadLine();

            var token = OAuth2Provider.GenerateRefreshTokenAsync(authCode, "http://127.0.0.1").Result;

            File.WriteAllText(RefreshTokenPath, JsonConvert.SerializeObject(token));
        }