Пример #1
0
        static void Main(string[] args)
        {
            // Authenticate Oauth2
            String CLIENT_ID     = "1046123799103-7mk8g2iok1dv9fphok8v2kv82hiqb0q6.apps.googleusercontent.com";
            String CLIENT_SECRET = "GeE-cD7PtraV0LqyoxqPnOpv";


            string[] scopes = new string[] { SiteVerificationService.Scope.Siteverification };
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
            {
                ClientId     = CLIENT_ID,
                ClientSecret = CLIENT_SECRET
            },
                                                                                    scopes,
                                                                                    Environment.UserName,
                                                                                    CancellationToken.None,
                                                                                    new FileDataStore("Daimto.SiteVerification.Auth.Store")
                                                                                    ).Result;

            // Create the service.
            var service = new SiteVerificationService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = "SiteVerification API Sample",
            });

            var x = service.WebResource.List().Execute();

            int i = 1;
        }
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            Console.WriteLine("Site Verification sample");
            Console.WriteLine("========================");

            UserCredential credential;

            using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { SiteVerificationService.Scope.Siteverification },
                    "user", CancellationToken.None, new FileDataStore("SiteVerification.VerifySite")).Result;
            }

            // Create the service.
            var service = new SiteVerificationService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = "SiteVerification API Sample",
            });

            RunVerification(service);

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Authenticate Oauth2
            String CLIENT_ID = "1046123799103-7mk8g2iok1dv9fphok8v2kv82hiqb0q6.apps.googleusercontent.com";
            String CLIENT_SECRET = "GeE-cD7PtraV0LqyoxqPnOpv";


            string[] scopes = new string[] { SiteVerificationService.Scope.Siteverification };
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
                                           {
                                            ClientId = CLIENT_ID,
                                            ClientSecret = CLIENT_SECRET
                                             },
                   scopes,
                     Environment.UserName,
                                                                CancellationToken.None,
                                                            new FileDataStore("Daimto.SiteVerification.Auth.Store")
                                                                ).Result;

            // Create the service.
            var service = new SiteVerificationService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = "SiteVerification API Sample",
            });

           var x =   service.WebResource.List().Execute();

           int i = 1;


        }
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            Console.WriteLine("Site Verification sample");
            Console.WriteLine("========================");

            UserCredential credential;
            using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { SiteVerificationService.Scope.Siteverification },
                    "user", CancellationToken.None, new FileDataStore("SiteVerification.VerifySite")).Result;
            }

            // Create the service.
            var service = new SiteVerificationService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "SiteVerification API Sample",
                });
            RunVerification(service);

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #5
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Site Verification sample");

            // Register the authenticator.
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials();
            provider.ClientIdentifier = credentials.ClientId;
            provider.ClientSecret = credentials.ClientSecret;
            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);

            // Create the service.
            var service = new SiteVerificationService();
            RunVerification(service);
            CommandLine.PressAnyKeyToExit();
        }
Пример #6
0
        /// <summary>
        /// This method contains the actual sample code.
        /// </summary>
        private static void RunVerification(SiteVerificationService service)
        {
            // Request user input.
            string site = Util.GetSingleLineClipboardContent(96);

            CommandLine.WriteAction("Please enter the URL of the site to verify:");
            CommandLine.RequestUserInput("URL", ref site);
            CommandLine.WriteLine();

            // Example of a GetToken call.
            CommandLine.WriteAction("Retrieving a meta token ...");
            var request = service.WebResource.GetToken(new SiteVerificationWebResourceGettokenRequest()
            {
                VerificationMethod = "meta",
                Site = new SiteVerificationWebResourceGettokenRequest.SiteData()
                {
                    Identifier = site,
                    Type       = "site"
                }
            });
            var response = request.Fetch();

            CommandLine.WriteResult("Token", response.Token);
            Util.SetClipboard(response.Token);
            CommandLine.WriteLine();

            CommandLine.WriteAction("Please place this token on your webpage now.");
            CommandLine.PressEnterToContinue();
            CommandLine.WriteLine();

            // Example of an Insert call.
            CommandLine.WriteAction("Verifiying...");
            var body = new SiteVerificationWebResourceResource();

            body.Site            = new SiteVerificationWebResourceResource.SiteData();
            body.Site.Identifier = site;
            body.Site.Type       = "site";
            var verificationResponse = service.WebResource.Insert(body, "meta").Fetch();

            CommandLine.WriteResult("Verification", verificationResponse.Id);
            CommandLine.WriteAction("Verification successful!");
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Site Verification sample");

            // Register the authenticator.
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials();

            provider.ClientIdentifier = credentials.ClientId;
            provider.ClientSecret     = credentials.ClientSecret;
            var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication);

            // Create the service.
            var service = new SiteVerificationService();

            RunVerification(service);
            CommandLine.PressAnyKeyToExit();
        }
        /// <summary>
        /// This method contains the actual sample code.
        /// </summary>
        private static void RunVerification(SiteVerificationService service)
        {
            // Request user input.
            Console.WriteLine("Please enter the URL of the site to verify:");
            var site = Console.ReadLine();

            Console.WriteLine();

            // Example of a GetToken call.
            Console.WriteLine("Retrieving a meta token ...");
            var request = service.WebResource.GetToken(new SiteVerificationWebResourceGettokenRequest()
            {
                VerificationMethod = "meta",
                Site = new SiteVerificationWebResourceGettokenRequest.SiteData()
                {
                    Identifier = site,
                    Type       = "site"
                }
            });
            var response = request.Execute();

            Console.WriteLine("Token: " + response.Token);
            Console.WriteLine();

            Console.WriteLine("Please place this token on your webpage now.");
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
            Console.WriteLine();

            // Example of an Insert call.
            Console.WriteLine("Verifying...");
            var body = new SiteVerificationWebResourceResource();

            body.Site            = new SiteVerificationWebResourceResource.SiteData();
            body.Site.Identifier = site;
            body.Site.Type       = "site";
            var verificationResponse = service.WebResource.Insert(body, "meta").Execute();

            Console.WriteLine("Verification:" + verificationResponse.Id);
            Console.WriteLine("Verification successful!");
        }
Пример #9
0
        /// <summary>
        /// This method contains the actual sample code.
        /// </summary>
        private static void RunVerification(SiteVerificationService service)
        {
            // Request user input.
            string site = Util.GetSingleLineClipboardContent(96);
            CommandLine.WriteAction("Please enter the URL of the site to verify:");
            CommandLine.RequestUserInput("URL", ref site);
            CommandLine.WriteLine();
            
            // Example of a GetToken call.
            CommandLine.WriteAction("Retrieving a meta token ...");
            var request = service.WebResource.GetToken(new SiteVerificationWebResourceGettokenRequest()
            {
                VerificationMethod = "meta",
                Site = new SiteVerificationWebResourceGettokenRequest.SiteData()
                {
                    Identifier = site,
                    Type = "site"
                }
            });
            var response = request.Fetch();
            CommandLine.WriteResult("Token", response.Token);
            Util.SetClipboard(response.Token);
            CommandLine.WriteLine();

            CommandLine.WriteAction("Please place this token on your webpage now.");
            CommandLine.PressEnterToContinue();
            CommandLine.WriteLine();

            // Example of an Insert call.
            CommandLine.WriteAction("Verifiying...");
            var body = new SiteVerificationWebResourceResource();
            body.Site = new SiteVerificationWebResourceResource.SiteData();
            body.Site.Identifier = site;
            body.Site.Type = "site";
            var verificationResponse = service.WebResource.Insert(body, "meta").Fetch();
            CommandLine.WriteResult("Verification", verificationResponse.Id);
            CommandLine.WriteAction("Verification successful!");
        }
        /// <summary>
        /// This method contains the actual sample code.
        /// </summary>
        private static void RunVerification(SiteVerificationService service)
        {
            // Request user input.
            Console.WriteLine("Please enter the URL of the site to verify:");
            var site = Console.ReadLine();
            Console.WriteLine();

            // Example of a GetToken call.
            Console.WriteLine("Retrieving a meta token ...");
            var request = service.WebResource.GetToken(new SiteVerificationWebResourceGettokenRequest()
            {
                VerificationMethod = "meta",
                Site = new SiteVerificationWebResourceGettokenRequest.SiteData()
                {
                    Identifier = site,
                    Type = "site"
                }
            });
            var response = request.Execute();
            Console.WriteLine("Token: " + response.Token);
            Console.WriteLine();

            Console.WriteLine("Please place this token on your webpage now.");
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
            Console.WriteLine();

            // Example of an Insert call.
            Console.WriteLine("Verifying...");
            var body = new SiteVerificationWebResourceResource();
            body.Site = new SiteVerificationWebResourceResource.SiteData();
            body.Site.Identifier = site;
            body.Site.Type = "site";
            var verificationResponse = service.WebResource.Insert(body, "meta").Execute();

            Console.WriteLine("Verification:" + verificationResponse.Id);
            Console.WriteLine("Verification successful!");
        }