Re: Better way to manage Ad Extensions?
Hi Anash Is it possible to just update a sitelink url with out deleting and re- creating? I've tried and got a "OperatorError.OPERATOR_NOT_SUPPORTED" error. Could you provide some code? Cheers David On Aug 18, 12:00 pm, AdWords API Advisor wrote: > Hi Joel, > > To add (or modify)SiteLinksfor a campaign, you have to > > - Check if there is an active SiteLinkExtension. If yes, remove it. > (Otherwise you will get > CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN). > - Add a new SiteLinkExtension with the desiredSiteLinks. > > The sample code in C# to check if a campaign has activesitelinksis > given below: > > long siteLinkExtensionId = -1; > > // Get the campaign ad extension containingsitelinks. > CampaignAdExtensionSelector selector = new > CampaignAdExtensionSelector(); > selector.campaignIds = new long[] { campaignId }; > selector.statuses = new CampaignAdExtensionStatus[] > { CampaignAdExtensionStatus.ACTIVE }; > > CampaignAdExtensionPage page = campaignExtensionService.get(selector); > if (page != null && page.entries != null) { > foreach (CampaignAdExtension extension in page.entries) { > if (extension.adExtension is SitelinksExtension) { > siteLinkExtensionId = extension.adExtension.id; > break; > } > } > > } > > If there are activesitelinks, then you can remove them as follows: > > if (siteLinkExtensionId == -1) { > return; // No activesitelinks, so no need to remove. > > } > > CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); > campaignAdExtension.campaignId = campaignId; > campaignAdExtension.adExtension = new AdExtension(); // no need to > create a SiteLinksExtension here, just an AdExtension would do. > campaignAdExtension.adExtension.id = siteLinkExtensionId; > > CampaignAdExtensionOperation operation = new > CampaignAdExtensionOperation(); > operati...@operator = Operator.REMOVE; > operation.operand = campaignAdExtension; > > CampaignAdExtensionReturnValue retVal = > campaignExtensionService.mutate(new CampaignAdExtensionOperation[] > { operation }); > > Now you can addsitelinksas follows: > > // create yoursitelinks. > Sitelink siteLink = new Sitelink(); > siteLink.displayText = "New albums"; > siteLink.destinationUrl = "http://www.example.com/albums/new";; > > SitelinksExtension siteLinkExtension = new SitelinksExtension(); > siteLinkExtension.sitelinks= new Sitelink[] {siteLink}; > > CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); > campaignAdExtension.adExtension = siteLinkExtension; > campaignAdExtension.campaignId = campaignId; > > CampaignAdExtensionOperation operation = new > CampaignAdExtensionOperation(); > operati...@operator = Operator.ADD; > operation.operand = campaignAdExtension; > > CampaignAdExtensionReturnValue retVal = > campaignExtensionService.mutate(new CampaignAdExtensionOperation[] > {operation}); > > Hope this helps. Let me know if you have more questions. > > Cheers, > Anash P. Oommen, > AdWords API Advisor. > > On Aug 18, 1:13 am, joel wrote: > > > > > To follow-up, I can't even seem to removeSiteLinksusing my > > methodology above. If I request theSiteLinksand then attempt a > > REMOVE operation, I get a NotEmptyError.EMPTY_LIST exception because > > my SitelinksExtension object has noSitelinksattached. If I don't > > remove and simply call another ADD while specifying the existing > > SitelinksExtension Id, I get an INVALID_ADEXTENSION_ID errors. Lastly, > > if I simply try to ADD without setting the Id or removing, then I get > > a CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN error. > > > Here's a snippet of my code: > > > CampaignAdExtensionServiceInterface extSvc = > > user.getService(AdWordsService.V201003.CAMPAIGN_AD_EXTENSION_SERVICE); > > > try > > { > > CampaignAdExtensionSelector selector = new > > CampaignAdExtensionSelector(); > > selector.setCampaignIds(new long[] > > { dbCampaign.getExternalIdAsLong() }); > > > // Get all campaign ad extensions. > > CampaignAdExtensionPage page = extSvc.get(selector); > > > // Display campaign ad extensions. > > if (page.getEntries() != null && > > page.getEntries().length > 0) > > { > > for (CampaignAdExtension campaignAdExtension : > > page.getEntries()) > > { > > if > > (campaignAdExtension.getAdExtension().getAdExtensionType().equals("Sitelink > > sExtension")) > > { > > SitelinksExtension ext = new > > SitelinksExtension(); > > > ext.setId(campaignAdExtension.getAdExtension().getId()); > > > CampaignAdExtension extension = new > > CampaignAdExtension(); > > > extension.setCampaignId(dbCampaign.getExternalIdAsLong()); > > extension.setAdExtension(ext); > > > CampaignAdExtensionOperation operation = > > new
Re: Better way to manage Ad Extensions?
Thank you, that worked. I was 99% of the way there. The only difference is that in my REMOVE operation I was using new SiteLinkExtension() whereas you used "new AdExtension(); // no need to create a SiteLinksExtension here, just an AdExtension would do." So for future reference for others: use the generic AdExtension object in REMOVES. Thanks, Joel On Aug 18, 7:00 am, AdWords API Advisor wrote: > Hi Joel, > > To add (or modify) SiteLinks for a campaign, you have to > > - Check if there is an active SiteLinkExtension. If yes, remove it. > (Otherwise you will get > CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN). > - Add a new SiteLinkExtension with the desired SiteLinks. > > The sample code in C# to check if a campaign has active sitelinks is > given below: > > long siteLinkExtensionId = -1; > > // Get the campaign ad extension containing sitelinks. > CampaignAdExtensionSelector selector = new > CampaignAdExtensionSelector(); > selector.campaignIds = new long[] { campaignId }; > selector.statuses = new CampaignAdExtensionStatus[] > { CampaignAdExtensionStatus.ACTIVE }; > > CampaignAdExtensionPage page = campaignExtensionService.get(selector); > if (page != null && page.entries != null) { > foreach (CampaignAdExtension extension in page.entries) { > if (extension.adExtension is SitelinksExtension) { > siteLinkExtensionId = extension.adExtension.id; > break; > } > } > > } > > If there are active sitelinks, then you can remove them as follows: > > if (siteLinkExtensionId == -1) { > return; // No active sitelinks, so no need to remove. > > } > > CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); > campaignAdExtension.campaignId = campaignId; > campaignAdExtension.adExtension = new AdExtension(); // no need to > create a SiteLinksExtension here, just an AdExtension would do. > campaignAdExtension.adExtension.id = siteLinkExtensionId; > > CampaignAdExtensionOperation operation = new > CampaignAdExtensionOperation(); > operati...@operator = Operator.REMOVE; > operation.operand = campaignAdExtension; > > CampaignAdExtensionReturnValue retVal = > campaignExtensionService.mutate(new CampaignAdExtensionOperation[] > { operation }); > > Now you can add sitelinks as follows: > > // create your sitelinks. > Sitelink siteLink = new Sitelink(); > siteLink.displayText = "New albums"; > siteLink.destinationUrl = "http://www.example.com/albums/new";; > > SitelinksExtension siteLinkExtension = new SitelinksExtension(); > siteLinkExtension.sitelinks = new Sitelink[] {siteLink}; > > CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); > campaignAdExtension.adExtension = siteLinkExtension; > campaignAdExtension.campaignId = campaignId; > > CampaignAdExtensionOperation operation = new > CampaignAdExtensionOperation(); > operati...@operator = Operator.ADD; > operation.operand = campaignAdExtension; > > CampaignAdExtensionReturnValue retVal = > campaignExtensionService.mutate(new CampaignAdExtensionOperation[] > {operation}); > > Hope this helps. Let me know if you have more questions. > > Cheers, > Anash P. Oommen, > AdWords API Advisor. > > On Aug 18, 1:13 am, joel wrote: > > > To follow-up, I can't even seem to remove SiteLinks using my > > methodology above. If I request the SiteLinks and then attempt a > > REMOVE operation, I get a NotEmptyError.EMPTY_LIST exception because > > my SitelinksExtension object has no Sitelinks attached. If I don't > > remove and simply call another ADD while specifying the existing > > SitelinksExtension Id, I get an INVALID_ADEXTENSION_ID errors. Lastly, > > if I simply try to ADD without setting the Id or removing, then I get > > a CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN error. > > > Here's a snippet of my code: > > > CampaignAdExtensionServiceInterface extSvc = > > user.getService(AdWordsService.V201003.CAMPAIGN_AD_EXTENSION_SERVICE); > > > try > > { > > CampaignAdExtensionSelector selector = new > > CampaignAdExtensionSelector(); > > selector.setCampaignIds(new long[] > > { dbCampaign.getExternalIdAsLong() }); > > > // Get all campaign ad extensions. > > CampaignAdExtensionPage page = extSvc.get(selector); > > > // Display campaign ad extensions. > > if (page.getEntries() != null && > > page.getEntries().length > 0) > > { > > for (CampaignAdExtension campaignAdExtension : > > page.getEntries()) > > { > > if > > (campaignAdExtension.getAdExtension().getAdExtensionType().equals("Sitelink > > sExtension")) > > { > > SitelinksExtension ext = new > > SitelinksExtension(); > > > ext.setId(campaignAdExtension.getAdExtension().getId()); > > > CampaignAdExtension extension = new > > CampaignAdExtension(); > > > extension.setCampaignId(dbCampaign.
Re: Better way to manage Ad Extensions?
Hi Joel, To add (or modify) SiteLinks for a campaign, you have to - Check if there is an active SiteLinkExtension. If yes, remove it. (Otherwise you will get CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN). - Add a new SiteLinkExtension with the desired SiteLinks. The sample code in C# to check if a campaign has active sitelinks is given below: long siteLinkExtensionId = -1; // Get the campaign ad extension containing sitelinks. CampaignAdExtensionSelector selector = new CampaignAdExtensionSelector(); selector.campaignIds = new long[] { campaignId }; selector.statuses = new CampaignAdExtensionStatus[] { CampaignAdExtensionStatus.ACTIVE }; CampaignAdExtensionPage page = campaignExtensionService.get(selector); if (page != null && page.entries != null) { foreach (CampaignAdExtension extension in page.entries) { if (extension.adExtension is SitelinksExtension) { siteLinkExtensionId = extension.adExtension.id; break; } } } If there are active sitelinks, then you can remove them as follows: if (siteLinkExtensionId == -1) { return; // No active sitelinks, so no need to remove. } CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); campaignAdExtension.campaignId = campaignId; campaignAdExtension.adExtension = new AdExtension(); // no need to create a SiteLinksExtension here, just an AdExtension would do. campaignAdExtension.adExtension.id = siteLinkExtensionId; CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation(); operati...@operator = Operator.REMOVE; operation.operand = campaignAdExtension; CampaignAdExtensionReturnValue retVal = campaignExtensionService.mutate(new CampaignAdExtensionOperation[] { operation }); Now you can add sitelinks as follows: // create your sitelinks. Sitelink siteLink = new Sitelink(); siteLink.displayText = "New albums"; siteLink.destinationUrl = "http://www.example.com/albums/new";; SitelinksExtension siteLinkExtension = new SitelinksExtension(); siteLinkExtension.sitelinks = new Sitelink[] {siteLink}; CampaignAdExtension campaignAdExtension = new CampaignAdExtension(); campaignAdExtension.adExtension = siteLinkExtension; campaignAdExtension.campaignId = campaignId; CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation(); operati...@operator = Operator.ADD; operation.operand = campaignAdExtension; CampaignAdExtensionReturnValue retVal = campaignExtensionService.mutate(new CampaignAdExtensionOperation[] {operation}); Hope this helps. Let me know if you have more questions. Cheers, Anash P. Oommen, AdWords API Advisor. On Aug 18, 1:13 am, joel wrote: > To follow-up, I can't even seem to remove SiteLinks using my > methodology above. If I request the SiteLinks and then attempt a > REMOVE operation, I get a NotEmptyError.EMPTY_LIST exception because > my SitelinksExtension object has no Sitelinks attached. If I don't > remove and simply call another ADD while specifying the existing > SitelinksExtension Id, I get an INVALID_ADEXTENSION_ID errors. Lastly, > if I simply try to ADD without setting the Id or removing, then I get > a CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN error. > > Here's a snippet of my code: > > CampaignAdExtensionServiceInterface extSvc = > user.getService(AdWordsService.V201003.CAMPAIGN_AD_EXTENSION_SERVICE); > > try > { > CampaignAdExtensionSelector selector = new > CampaignAdExtensionSelector(); > selector.setCampaignIds(new long[] > { dbCampaign.getExternalIdAsLong() }); > > // Get all campaign ad extensions. > CampaignAdExtensionPage page = extSvc.get(selector); > > // Display campaign ad extensions. > if (page.getEntries() != null && > page.getEntries().length > 0) > { > for (CampaignAdExtension campaignAdExtension : > page.getEntries()) > { > if > (campaignAdExtension.getAdExtension().getAdExtensionType().equals("Sitelink > sExtension")) > { > SitelinksExtension ext = new > SitelinksExtension(); > > ext.setId(campaignAdExtension.getAdExtension().getId()); > > CampaignAdExtension extension = new > CampaignAdExtension(); > > extension.setCampaignId(dbCampaign.getExternalIdAsLong()); > extension.setAdExtension(ext); > > CampaignAdExtensionOperation operation = > new CampaignAdExtensionOperation(); > operation.setOperand(extension); > operation.setOperator(Operator.REMOVE); > > extSvc.mutate(new > CampaignAdExtensionOperation[] { operation }); > > break; > } > } > } > } > catch (Exception e) > { > Service
Re: Better way to manage Ad Extensions?
To follow-up, I can't even seem to remove SiteLinks using my methodology above. If I request the SiteLinks and then attempt a REMOVE operation, I get a NotEmptyError.EMPTY_LIST exception because my SitelinksExtension object has no Sitelinks attached. If I don't remove and simply call another ADD while specifying the existing SitelinksExtension Id, I get an INVALID_ADEXTENSION_ID errors. Lastly, if I simply try to ADD without setting the Id or removing, then I get a CANNOT_HAVE_MULTIPLE_SITELINKS_EXTENSIONS_PER_CAMPAIGN error. Here's a snippet of my code: CampaignAdExtensionServiceInterface extSvc = user.getService(AdWordsService.V201003.CAMPAIGN_AD_EXTENSION_SERVICE); try { CampaignAdExtensionSelector selector = new CampaignAdExtensionSelector(); selector.setCampaignIds(new long[] { dbCampaign.getExternalIdAsLong() }); // Get all campaign ad extensions. CampaignAdExtensionPage page = extSvc.get(selector); // Display campaign ad extensions. if (page.getEntries() != null && page.getEntries().length > 0) { for (CampaignAdExtension campaignAdExtension : page.getEntries()) { if (campaignAdExtension.getAdExtension().getAdExtensionType().equals("SitelinksExtension")) { SitelinksExtension ext = new SitelinksExtension(); ext.setId(campaignAdExtension.getAdExtension().getId()); CampaignAdExtension extension = new CampaignAdExtension(); extension.setCampaignId(dbCampaign.getExternalIdAsLong()); extension.setAdExtension(ext); CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation(); operation.setOperand(extension); operation.setOperator(Operator.REMOVE); extSvc.mutate(new CampaignAdExtensionOperation[] { operation }); break; } } } } catch (Exception e) { ServiceResult failure = GoogleUtils.populateFaultToServiceResult(e); results.put(dbCampaign, failure); continue; } // Now add the new SiteLinks List lOperations = new ArrayList(); List lSiteLinks = hmAdds.get(dbCampaign); for (DBSiteLink dbSiteLink : lSiteLinks) { Sitelink sl = new Sitelink(); sl.setDestinationUrl(dbSiteLink.getDestinationUrl()); sl.setDisplayText(dbSiteLink.getDisplayText()); SitelinksExtension ext = new SitelinksExtension(); ext.setSitelinks(new Sitelink[] { sl }); CampaignAdExtension extension = new CampaignAdExtension(); extension.setCampaignId(dbCampaign.getExternalIdAsLong()); extension.setAdExtension(ext); CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation(); operation.setOperand(extension); operation.setOperator(Operator.ADD); lOperations.add(operation); } CampaignAdExtensionOperation[] operations = lOperations.toArray(new CampaignAdExtensionOperation[lOperations.size()]); extSvc.mutate(operations); Thanks for any help, Joel On Aug 17, 3:16 pm, joel wrote: > I'm implementing an API tool to manage Sitelinks. The API objects only > provide an Id on the AdExtension object, and not for the Sitelink > object. Therefore I can't add/remove/update individual Sitelinks for a > Campaign, I need to delete the previous set of Sitelinks and re-add > all of them. Since I can't modify these, I also don't see the need for > the Id on the AdExtension object anyways. It seems as if the only way > to work with this API is to always have my code: > > 1) GET/request any existing Sitelink AdExtension > 2) Delete the existing SiteLink AdExtension if one does exist > 3) Add a new one with my new list of Sitelinks > > Is there a better way to do this? If not, can you please consider > adding Ids to the Sitelink objects so that those can be added/removed > individually. > > Thanks, > > Joel -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ 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 adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en