Looks like the value linkid on line 39 is null and the api doesn;t
allow nullable values.
I added

if (linkId == null)
        {
            linkId = 0;
        }

to just before

RemoveActiveSitelinkExtension(campaignId,
long.Parse(linkId.Value.ToString()));

Now get the error

Exception Details: System.Web.Services.Protocols.SoapException:
[RangeError.TOO_LOW @ operations[0].operand.adExtension.id.id]

Source Error: (Line: 84)


Line 82:         operation.@operator = Operator.REMOVE;
Line 83:         operation.operand = campaignAdExtension;
Line 84:         CampaignAdExtensionReturnValue retVal =
Line 85:             campaignExtensionService.mutate(new
CampaignAdExtensionOperation[] {
Line 86:           operation });



On Nov 14, 5:41 pm, Paigey <chiswicki...@googlemail.com> wrote:
> Hi all, back in August I posted some requests for help with how adding
> and removing sitelinks works and would like to say a big thanks to
> Pete Lavetsky and Anash Oommen for their replies and advice.
>
> Since the last post I have built an app for the google heads here to
> use to keep track of sitelinks across various accounts but have become
> a bit stuck on actually uploading sitelinks to an account. I'm using a
> particular account and campaign as a test account whilst checking
> everything is running smoothly but when I try to run even the example
> c# that Anash provided 
> herehttp://adwordsapi.blogspot.com/2010/09/discover-v201003-using-ad-site...
> I get errors when trying to parse the campaignid. I've had a quick
> look around the web and seen a few people with similar problems but
> not managed to find a solution that works. I've also tried the
> Google.Api.Ads.AdWords.v201101 version but get the same error trying
> to parse the campaignid.
>
> The code I have based on Anash's example at the url above is further
> down and the error I get back is:
>
> Exception Details: System.FormatException: Input string was not in a
> correct format. (Line: 39)
>
> Line 37:         if (linkId != 1)
> Line 38:         {
> Line 39:             RemoveActiveSitelinkExtension(campaignId,
> long.Parse(linkId.ToString()));
> Line 40:         }
> Line 41:
>
> //Begin code
> public static AdWordsUser user = new AdWordsUser();
>     public static CampaignAdExtensionService campaignExtensionService
> =
> (CampaignAdExtensionService)user.GetService(AdWordsService.v201003.Campaign­AdExtensionService);
>
>     protected void Page_Load(object sender, EventArgs e)
>     {
>
>     }
>
>     protected void Send_Click(object sender, EventArgs e)
>     {
>         string cid = "12345678"; //not real, just an example id
>         long campaignId = long.Parse(cid);
>
>         Sitelink siteLink1 = new Sitelink();
>         siteLink1.displayText = "Bet Now Test";
>         siteLink1.destinationUrl = "http://www.sportingbet.com";;
>
>         Sitelink siteLink2 = new Sitelink();
>         siteLink2.displayText = "Free Bet Test";
>         siteLink2.destinationUrl = "http://www.sportingbet.com";;
>
>         long? linkId = GetActiveSitelinkExtension(campaignId);
>
>         if (linkId != 1)
>         {
>             RemoveActiveSitelinkExtension(campaignId,
> long.Parse(linkId.ToString()));
>         }
>
>         AddSitelinks(campaignId, new Sitelink[] { siteLink1,
> siteLink2 });
>     }
>
>     private long? GetActiveSitelinkExtension(long campaignId)
>     {
>         long? siteLinkExtensionId = null;
>
>         // 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;
>                 }
>             }
>         }
>         return siteLinkExtensionId;
>     }
>
>     private SitelinksExtension RemoveActiveSitelinkExtension(long
> campaignId, long siteLinkExtensionId)
>     {
>         CampaignAdExtension campaignAdExtension = new
> CampaignAdExtension();
>         campaignAdExtension.campaignId = campaignId;
>         campaignAdExtension.adExtension = new AdExtension();
>         campaignAdExtension.adExtension.id = siteLinkExtensionId;
>
>         CampaignAdExtensionOperation operation = new
> CampaignAdExtensionOperation();
>         operation.@operator = Operator.REMOVE;
>         operation.operand = campaignAdExtension;
>         CampaignAdExtensionReturnValue retVal =
>             campaignExtensionService.mutate(new
> CampaignAdExtensionOperation[] {
>           operation });
>         if (retVal != null && retVal.value != null &&
> retVal.value.Length > 0 &&
>             retVal.value[0].adExtension is SitelinksExtension)
>         {
>             return (SitelinksExtension)retVal.value[0].adExtension;
>         }
>         else
>         {
>             return null;
>         }
>     }
>
>     private SitelinksExtension AddSitelinks(long campaignId,
> Sitelink[]
>     siteLinks)
>     {
>         SitelinksExtension siteLinkExtension = new
> SitelinksExtension();
>         siteLinkExtension.sitelinks = siteLinks;
>
>         CampaignAdExtension campaignAdExtension = new
> CampaignAdExtension();
>         campaignAdExtension.adExtension = siteLinkExtension;
>         campaignAdExtension.campaignId = campaignId;
>
>         CampaignAdExtensionOperation operation = new
> CampaignAdExtensionOperation();
>         operation.@operator = Operator.ADD;
>         operation.operand = campaignAdExtension;
>
>         CampaignAdExtensionReturnValue retVal =
>             campaignExtensionService.mutate(new
> CampaignAdExtensionOperation[] {
>           operation });
>         if (retVal != null && retVal.value != null &&
> retVal.value.Length > 0)
>         {
>             return retVal.value[0].adExtension as SitelinksExtension;
>         }
>         else
>         {
>             return null;
>         }
>     }
> //end code
>
> Any help with this would be great!
>
> Kind regards
>
> Paigey

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