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 <adwordsapiadvi...@google.com> 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 <joel.patt...@gmail.com> 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 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 newSiteLinks > > List<CampaignAdExtensionOperation> lOperations = new > > ArrayList<CampaignAdExtensionOperation>(); > > > List<DBSiteLink> 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 <joel.patt...@gmail.com> wrote: > > > > I'm implementing an API tool to manageSitelinks. The API objects only > > > provide an Id on the AdExtension object, and not for the Sitelink > > > object. Therefore I can't add/remove/update individualSitelinksfor a > > > Campaign, I need to delete the previous set ofSitelinksand 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 ofSitelinks > > > > 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