public static void deleteCampaignCriteria(AdWordsUser user, long
campaignId,
 
CampaignCriterionService campaignCriterionService)
        {
            List<CampaignCriterionOperation> operations = new
List<CampaignCriterionOperation>();

            //step 1. Get all criteria LANGUAGE, LOCATION, and
PROXIMITY of a Campaign
            Selector selector = new Selector();
            selector.fields = new string[] { "Id", "CampaignId",
"CriteriaType" };

            Predicate predicate = new Predicate();
            predicate.@operator = PredicateOperator.EQUALS;
            predicate.field = "CampaignId";
            predicate.values = new string[] { campaignId.ToString() };

            Predicate predicate2 = new Predicate();
            predicate2.@operator = PredicateOperator.IN;
            predicate2.field = "CriteriaType";
            predicate2.values = new string[] { "LANGUAGE", "LOCATION",
"PROXIMITY" };

            selector.predicates = new Predicate[] { predicate,
predicate2 };

            try
            {
                CampaignCriterionPage page =
campaignCriterionService.get(selector);
                if (page != null && page.entries != null)
                {
                    //step 2. Delete criteria
                    foreach (CampaignCriterion campaignCriterion in
page.entries)
                    {
                            CampaignCriterionOperation operation = new
CampaignCriterionOperation();
                            operation.operand = campaignCriterion;
                            operation.@operator = Operator.REMOVE;

                            operations.Add(operation);
                    }


                    if (operations.Count > 0)
                    {
                        CampaignCriterionReturnValue retVal =
campaignCriterionService.mutate(operations.ToArray());

                        //display deleted criteria
                        if (retVal != null && retVal.value != null &&
retVal.value.Length > 0)
                        {
                            foreach (CampaignCriterion temp in
retVal.value)
                            {
                                Console.WriteLine("Campaign criterion
with campaign id = \"{0}\", criterion id = " +
                                     "\"{1}\" and type = \"{2}\" was
deleted.", temp.campaignId, temp.criterion.id,
temp.criterion.CriterionType);
                            }
                        }
                        else
                        {
                            Console.WriteLine("No campaign criteria
were deleted.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No campaign criteria were
found.");
                }
            }
            catch (Exception ex)
            {
 
Logger.LogThis(string.Format("deleteCampaignCriteria(): Exception says
\"{0}\"", ex.Message));
            }
        }


public static void addCampaignCriteria(AdWordsUser user, long
campaignId,
 
CampaignCriterion[] criteria,
 
CampaignCriterionService campaignCriterionService,
                                                    googleNameAndID
googleCampaign)
        {
            List<CampaignCriterionOperation> operations = new
List<CampaignCriterionOperation>();

            foreach (CampaignCriterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new
CampaignCriterionOperation();
                operation.@operator = Operator.ADD;
                operation.operand = criterion;
                operations.Add(operation);
            }

            try
            {
                CampaignCriterionReturnValue retVal =
campaignCriterionService.mutate(operations.ToArray());

                //display added criteria
                if (retVal != null && retVal.value != null &&
retVal.value.Length > 0)
                {
                    foreach (CampaignCriterion temp in retVal.value)
                    {
                        Console.WriteLine("Campaign criterion with
campaign id = \"{0}\", criterion id = " +
                                             "\"{1}\" and type =
\"{2}\" was added.",
                                             temp.campaignId,
                                             temp.criterion.id,
 
temp.criterion.CriterionType);
                    }
                }
                else
                {
                    Console.WriteLine("No campaign criteria were
added.");
                }
            }
            catch (Exception ex)
            {
                Logger.LogThis(string.Format("addCampaignCriteria()
inside UpdateTheseGoogleGEOTargets(): " + googleCampaign.gname + " " +
googleCampaign.gid + "\n" + ex.ToString(), Logger.MsgTypeEnum.Error));
            }
        }

On Jan 6, 2:47 pm, Minh Le <[email protected]> wrote:
> Could anyone help me solve this issue in urgent?
>
> http://groups.google.com/group/adwords-api/browse_thread/thread/cf278...
>
> Now I'm doing this process:
>
> - get all the criteria of a campaign
>
> - delete those criteria
>
> - add new criteria to the campaign
>
> The criteria includes Language, Location and Proximity.
>
> I have no choice than delete all the criteria before adding the new
> ones because I can be able to retrieve the criterion ID for all the
> criteria, but I cannot match them with the new ones because there are
> no ids for the new ones. Even if I can, I have to run a huge number of
> FOR loop to match the ids to see if I need to leave or remove the
> criteria.
>
> I really don't understand why Google team removed the SET operator!!!

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords 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

Reply via email to