internal static void Main(string[] args)
        {
            Console.WriteLine("Content API for Shopping Orders Sample");
            Console.WriteLine("============================================");

            var options = new Options();

            CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

            if (options.ConfigPath == null)
            {
                options.ConfigPath = defaultPath;
            }

            MerchantConfig config = MerchantConfig.Load(options.ConfigPath);

            var initializer = Authenticator.authenticate(config, ShoppingContentService.Scope.Content);

            if (initializer == null)
            {
                Console.WriteLine("Failed to authenticate, so exiting.");
                return;
            }

            // Create the (sandbox-using) service.
            var service = new SandboxService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = initializer,
                ApplicationName       = config.ApplicationName,
            });

            OrdersSample ordersSample = new OrdersSample(service);

            ordersSample.RunCalls(config.MerchantId);
        }
Пример #2
0
 internal override void initializeConfig(bool noConfig)
 {
     if (noConfig)
     {
         config = new MerchantConfig();
     }
     else
     {
         config = MerchantConfig.Load(CliOptions.ConfigPath);
     }
 }
Пример #3
0
        internal static void Main(string[] args)
        {
            Console.WriteLine("Content API for Shopping Command Line Sample");
            Console.WriteLine("============================================");

            MerchantConfig config = MerchantConfig.Load();

            var initializer = Authenticator.authenticate(config, ShoppingContentService.Scope.Content);

            if (initializer == null)
            {
                Console.WriteLine("Failed to authenticate, so exiting.");
                return;
            }

            // Create the service.
            var service = new ShoppingContentService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = initializer,
                ApplicationName       = config.ApplicationName,
            });

            AccountsSample        accountsSample        = new AccountsSample(service);
            AccountstatusesSample accountstatusesSample =
                new AccountstatusesSample(service, MaxListPageSize);
            AccounttaxSample      accounttaxSample      = new AccounttaxSample(service);
            DatafeedsSample       datafeedsSample       = new DatafeedsSample(service);
            ProductsSample        productsSample        = new ProductsSample(service, MaxListPageSize);
            ProductstatusesSample productstatusesSample =
                new ProductstatusesSample(service, MaxListPageSize);
            ShippingsettingsSample   shippingsettingsSample   = new ShippingsettingsSample(service);
            MultiClientAccountSample multiClientAccountSample = new MultiClientAccountSample(service);

            if (!config.IsMCA)
            {
                // Non-MCA calls
                productsSample.RunCalls(config.MerchantId, config.WebsiteURL);
                productstatusesSample.RunCalls(config.MerchantId);
                datafeedsSample.RunCalls(config.MerchantId);
                accountstatusesSample.RunCalls(config.MerchantId);
                accountsSample.RunCalls(config.MerchantId, config.AccountSampleUser, config.AccountSampleAdWordsCID);
                accounttaxSample.RunCalls(config.MerchantId);
                shippingsettingsSample.RunCalls(config.MerchantId);
            }
            else
            {
                // MCA calls
                accountstatusesSample.RunMultiCalls(config.MerchantId);
                multiClientAccountSample.RunCalls(config.MerchantId);
            }
        }
Пример #4
0
 internal override void initializeConfig()
 {
     config = MerchantConfig.Load(CliOptions.ConfigPath);
 }
Пример #5
0
        // Retrieve the following configuration fields using the Content API:
        // - IsMCA
        // - WebsiteUrl
        // Also use the first Merchant Center account to which the authenticated user has access
        // if no Merchant Center ID was provided.
        internal void retrieveConfiguration(ShoppingContentService service, MerchantConfig config)
        {
            Console.WriteLine("Retrieving information for authenticated user.");
            var authinfo = service.Accounts.Authinfo().Execute();

            if (authinfo.AccountIdentifiers.Count == 0)
            {
                throw new ArgumentException(
                          "Authenticated user has no access to any Merchant Center accounts.");
            }
            if (config.MerchantId == null)
            {
                var firstAccount = authinfo.AccountIdentifiers[0];
                if (firstAccount.MerchantId == null)
                {
                    config.MerchantId = firstAccount.AggregatorId;
                }
                else
                {
                    config.MerchantId = firstAccount.MerchantId;
                }
                Console.WriteLine(
                    "Using Merchant Center {0} for running samples.", config.MerchantId.Value);
            }
            ulong merchantId = config.MerchantId.Value;

            // We detect whether the requested Merchant Center ID is an MCA by checking
            // Accounts.authinfo(). If it is an MCA, then the authenticated user must be
            // a user of that account, which means it'll be listed here, and it must
            // appear in the AggregatorId field of one of the AccountIdentifier entries.
            config.IsMCA = false;
            foreach (var accountId in authinfo.AccountIdentifiers)
            {
                if (merchantId == accountId.AggregatorId)
                {
                    config.IsMCA = true;
                    break;
                }
                if (merchantId == accountId.MerchantId)
                {
                    break;
                }
            }
            Console.WriteLine("Merchant Center {0} is{1} an MCA.",
                              merchantId,
                              config.IsMCA ? "" : " not");

            var account = service.Accounts.Get(merchantId, merchantId).Execute();

            if (!String.IsNullOrEmpty(account.WebsiteUrl))
            {
                config.WebsiteURL = account.WebsiteUrl;
                Console.WriteLine(
                    "Website for Merchant Center {0}: {1}",
                    merchantId,
                    config.WebsiteURL);
            }
            else
            {
                Console.WriteLine("Merchant Center {0} has no configured website.", merchantId);
            }
        }