Пример #1
0
        /// <summary>Snippet for RunOfflineUserDataJobAsync</summary>
        public async Task RunOfflineUserDataJobResourceNamesAsync()
        {
            // Snippet: RunOfflineUserDataJobAsync(OfflineUserDataJobName, CallSettings)
            // Additional: RunOfflineUserDataJobAsync(OfflineUserDataJobName, CancellationToken)
            // Create client
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = await OfflineUserDataJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            OfflineUserDataJobName resourceName = OfflineUserDataJobName.FromCustomerOfflineUserDataUpdate("[CUSTOMER_ID]", "[OFFLINE_USER_DATA_UPDATE_ID]");
            // Make the request
            Operation <Empty, Empty> response = await offlineUserDataJobServiceClient.RunOfflineUserDataJobAsync(resourceName);

            // Poll until the returned long-running operation is complete
            Operation <Empty, Empty> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Empty result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <Empty, Empty> retrievedResponse = await offlineUserDataJobServiceClient.PollOnceRunOfflineUserDataJobAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Empty retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
        /// <summary>Snippet for RunOfflineUserDataJobAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task RunOfflineUserDataJobAsync()
        {
            // Create client
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = await OfflineUserDataJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/offlineUserDataJobs/[OFFLINE_USER_DATA_UPDATE_ID]";
            // Make the request
            Operation <Empty, Empty> response = await offlineUserDataJobServiceClient.RunOfflineUserDataJobAsync(resourceName);

            // Poll until the returned long-running operation is complete
            Operation <Empty, Empty> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Empty result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <Empty, Empty> retrievedResponse = await offlineUserDataJobServiceClient.PollOnceRunOfflineUserDataJobAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Empty retrievedResult = retrievedResponse.Result;
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="conversionActionId">The ID of a store sales conversion action.</param>
        /// <param name="customKey">Optional: If uploading data with custom key and values, also specify this value.</param>
        /// <param name="offlineUserDataJobType">The type of user data in the job (first or third
        ///     party). If you have an official store sales partnership with Google, use
        ///     StoreSalesUploadThirdParty. Otherwise, use StoreSalesUploadFirstParty or
        ///     omit this parameter.</param>
        /// <param name="externalId">Optional (but recommended) external ID to identify the offline
        ///     user data job.</param>
        /// <param name="advertiserUploadDateTime">Date and time the advertiser uploaded data to the
        ///     partner. Only required if uploading third party data.</param>
        /// <param name="bridgeMapVersionId">Version of partner IDs to be used for uploads. Only
        ///     required if uploading third party data.</param>
        /// <param name="partnerId">ID of the third party partner. Only required if uploading third
        ///     party data.</param>
        public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
                        string customKey = null,
                        OfflineUserDataJobType offlineUserDataJobType =
                        OfflineUserDataJobType.StoreSalesUploadFirstParty,
                        long?externalId           = null, string advertiserUploadDateTime = null,
                        string bridgeMapVersionId = null, long?partnerId                  = null)
        {
            // Get the OfflineUserDataJobServiceClient.
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient =
                client.GetService(Services.V4.OfflineUserDataJobService);

            // Ensure that a valid job type is provided.
            if (offlineUserDataJobType != OfflineUserDataJobType.StoreSalesUploadFirstParty &
                offlineUserDataJobType != OfflineUserDataJobType.StoreSalesUploadThirdParty)
            {
                Console.WriteLine("Invalid job type specified, defaulting to First Party.");
                offlineUserDataJobType = OfflineUserDataJobType.StoreSalesUploadFirstParty;
            }

            try
            {
                // Creates an offline user data job for uploading transactions.
                string offlineUserDataJobResourceName =
                    CreateOfflineUserDataJob(offlineUserDataJobServiceClient, customerId,
                                             offlineUserDataJobType, externalId, advertiserUploadDateTime,
                                             bridgeMapVersionId, partnerId, customKey);

                // Adds transactions to the job.
                AddTransactionsToOfflineUserDataJob(offlineUserDataJobServiceClient, customerId,
                                                    offlineUserDataJobResourceName, conversionActionId);

                // Issues an asynchronous request to run the offline user data job.
                offlineUserDataJobServiceClient.RunOfflineUserDataJobAsync(
                    offlineUserDataJobResourceName);

                Console.WriteLine("Sent request to asynchronously run offline user data job " +
                                  $"{offlineUserDataJobResourceName}.");

                // Offline user data jobs may take up to 24 hours to complete, so instead of waiting
                // for the job to complete, retrieves and displays the job status once and then
                // prints the query to use to check the job again later.
                CheckJobStatus(client, customerId, offlineUserDataJobResourceName);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }