Google Ads API V1 Sitelink

91 views
Skip to first unread message

rentca...@gmail.com

unread,
Mar 13, 2019, 4:15:30 PM3/13/19
to AdWords API and Google Ads API Forum
Hello,

I'm receiving the following error when I try to create a sitelink extension.

Google Error:  Status(StatusCode=InvalidArgument, Detail="Request contains an invalid argument.")

Please see attached for ExtensionFeedItemOperations request information.

Below is the code I'm using:

            string extensionResourceName = string.Empty;
            List<ExtensionFeedItem> extensionFeedItem = new List<ExtensionFeedItem>();
            List<ExtensionFeedItemOperation> extensionFeedItemOperations = new List<ExtensionFeedItemOperation>();

            if (SLDataList.Count == 0) { return "Missing SiteLinks"; }

            GoogleAdsServiceClient googleAdsService = Client.GetService(Services.V1.GoogleAdsService);

            ExtensionFeedItemServiceClient serviceClient = Client.GetService(Services.V1.ExtensionFeedItemService);

            foreach (SiteLinkData SiteLink in SLDataList )
            {
                extensionFeedItem.Add(CreateSiteLinkExtensionFeedItem(CreateSiteLinkFeedItem(SiteLink.SiteLinkText, SiteLink.SiteLinkURL)));
            }

            extensionFeedItemOperations = BuildExtensionOperation(extensionFeedItem);

            try
            {
                MutateExtensionFeedItemsResponse response = serviceClient.MutateExtensionFeedItems(CustomerId.ToString(), extensionFeedItemOperations.ToArray());
                if (response.Results.Count > 0) { extensionResourceName = response.Results[0].ResourceName; }
            }
            catch (Exception e)
            {
                return "Google Error:  " + e.Message + "  StackTrace:  " + e.StackTrace.ToString();
            }
            if (extensionResourceName.Length > 0) { return "success"; } else { return ""; }
        }

        private SitelinkFeedItem CreateSiteLinkFeedItem(string SiteLinkText, string SiteLinkURL)
        {            
            return new SitelinkFeedItem()
            {
                LinkText = SiteLinkText,
                //FinalUrls = SiteLinkURL,                  
                Line1 = "Teating stuff",
                Line2 = "more testing"
                  
            };
        }

        private ExtensionFeedItem CreateSiteLinkExtensionFeedItem(SitelinkFeedItem sitelinkFeedItem)
        {
            return new ExtensionFeedItem()
            {  
                SitelinkFeedItem = sitelinkFeedItem,
                Status = FeedItemStatus.Enabled 
            };
        }

        private List<ExtensionFeedItemOperation> BuildExtensionOperation(List<ExtensionFeedItem> extensionFeedItems)
        {
            List<ExtensionFeedItemOperation> extensionOperations = new List<ExtensionFeedItemOperation>();
             
            for (int i = 0; i < extensionFeedItems.Count; i++)
            {
                ExtensionFeedItemOperation extensionOperation = new ExtensionFeedItemOperation()
                { 
                    Create = extensionFeedItems[i]
                };
                extensionOperations.Add(extensionOperation);
            }

            return extensionOperations;
        }

I'm also unable to set FinalUrls because its read only (see attached).
        [DebuggerNonUserCode]
        public RepeatedField<string> FinalUrls { get; }

Not sure what I'm missing.  I would really appreciate it if someone could explain how to create a Sitelink extension using Google Ads API V1.

KDJ
SiteLinkIssue.docx

googleadsapi...@google.com

unread,
Mar 13, 2019, 11:17:11 PM3/13/19
to AdWords API and Google Ads API Forum
Hi,

To further investigate this, could you provide the complete request and response logs when you encountered the error? You may refer here on how to enable the logging in Java client library (if you haven't done so). Please reply via Reply privately to author.

Thanks and regards,
Luis
Google Ads API Team


--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
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 "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/b8c6302d-2d01-4c88-9c15-bbe261afcf1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages