using Google.Ads.GoogleAds;
using Google.Ads.GoogleAds.Lib;
using Google.Ads.GoogleAds.V11.Services;
using Google.Api.Gax;
using meedee8.ads.GoogleAdsApi.Helper;
using meedee8.ads.GoogleAdsApi.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace meedee8.ads.GoogleAdsApi.Campaigns
{
    public class GetCampaign : ICampaign
    {
        private const int PAGE_SIZE = 1_000;
        /// <summary>
        /// This will return the All campaign that linked to selected 
AdsAccount
        /// </summary>
        /// <param name="AccountID"></param>
        /// <returns>Campaign</returns>
        public List<CampaignSetting> GetCampaignDetails(string AccountID)
        {
            GoogleAdsClient client = new GoogleAdsClient();
            List<CampaignSetting> Campaign = new List<CampaignSetting>();
            GoogleAdsServiceClient googleAdsService = 
client.GetService(Services.V11.GoogleAdsService);
            SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
            {
                PageSize = PAGE_SIZE,
                Query = @"SELECT
                           campaign.id,
                            campaign.name,
                            campaign.status,
                            campaign.start_date,
                            campaign.end_date,
                            campaign.network_settings.target_content_network
                        FROM campaign
                        ORDER BY campaign.id",
                CustomerId = AccountID
            };
            object sync = new Object();
            try
            {
                PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> 
searchPagedResponse = googleAdsService.Search(request);
                Parallel.ForEach(searchPagedResponse, response =>
                {
                    lock (sync)
                    {
                        Campaign.Add(new CampaignSetting()
                        {
                            CampaignID = response.Campaign.Id.ToString(),
                            Name = response.Campaign.Name,
                            Status = response.Campaign.Status.ToString(),
                            StartDate = response.Campaign.StartDate,
                            EndDate = response.Campaign.EndDate,
                        });
                    }

                });
            }
            catch(Exception ee)
            {

            }
            return Campaign.OrderByDescending(c => c.StartDate).ToList();
        }
    }
}

On Tuesday, September 13, 2022 at 11:38:58 AM UTC+5:30 Sadik Azami wrote:

> Hi Team,
>
> Getting below error for getting campaigns list-
>
> Detail="Deadline Exceeded", 
> DebugException="Grpc.Core.Internal.CoreErrorDetailException: 
> {"created":"@1663045617.542000000","description":"Deadline 
> Exceeded","file":"..\..\..\src\core\ext\filters\deadline\deadline_filter.cc","file_line":81,"grpc_status":4}")
>
> Thanks
> Sadik
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/5216d3fe-47e7-4870-a9fd-e9571a558758n%40googlegroups.com.
  • De... Sadik Azami
    • ... Sadik Azami
      • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to