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<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 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

Reply via email to