Re: dotnet api and sitelinks take 2

2011-11-21 Thread Paigey
Hi Anash,

Have managed to fix the problem with passing the campaignid and touch
wood no more errors.
Using v201101 and the main problem I was having was the example I was
using which you posted awhile ago targeted v201003 of the api and I
was trying to incorporate code from
v201101 so it was getting confused with some of the calls to the api.
I rewrote the example you posted (http://www.google.com/url?
sa=D&q=http://adwordsapi.blogspot.com/2010/09/discover-v201003-using-
ad-sitelinks.html&usg=AFQjCNFavCUZxtHzd3JnEyoRdmlv068VYA) to work with
v201101. Not much needed to change but let me know if you want a copy
and I'll email you the cs file.

In v201101 as long as the CamapignId's are strings to begin with use
Int64.Parse instead of long.Parse as below:

string campaignid = "123456";
long campaignId = Int64.Parse(campaignid);

In my sql database I was storing the campaignids as integers but due
to the length of the campaignid's being to big for type int, when
parsing them back through the api it was throwing the identity not
found error!
All I did was change the datatype in the database for campaignids to a
string and used Int64.Parse to parse them as long and everything is
working fine now!

I suppose like everything in life it's just a case of trial and error
but got there in the end.

Thanks for your help as always

Paigey


On Nov 18, 5:42 pm, "Anash P. Oommen"  wrote:
> Hi Paigey,
>
> I'd recommend you move to v201109. That would require some changes in your
> code though. I don't have a handy example for getAllSiteLinks, you could
> tryhttp://code.google.com/p/google-api-adwords-dotnet/source/browse/trun...as
> a starting point. As for others, you can refer 
> tohttp://code.google.com/p/google-api-adwords-dotnet/source/browse/trun...
>  andhttp://code.google.com/p/google-api-adwords-dotnet/source/browse/trun
> Feel free to follow up with questions that you may have.
>
> Finally, about long.Parse: You could try long.TryParse, that won't throw an
> exception. However, NOT getting campaignId is a more serious problem, I
> feel we should work to fix that problem first :)
>
> Cheers,
> Anash P. Oommen,
> AdWords API Advisor.

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


Re: dotnet api and sitelinks take 2

2011-11-18 Thread Anash P. Oommen
Hi Paigey,

I'd recommend you move to v201109. That would require some changes in your 
code though. I don't have a handy example for getAllSiteLinks, you could 
try 
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/examples/csharp/v201109/GetAllCampaignAdExtensions.cs
 as 
a starting point. As for others, you can refer to 
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/examples/csharp/v201109/AddSiteLinks.cs
 and 
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/examples/csharp/v201109/DeleteSitelinks.cs.
 
Feel free to follow up with questions that you may have.

Finally, about long.Parse: You could try long.TryParse, that won't throw an 
exception. However, NOT getting campaignId is a more serious problem, I 
feel we should work to fix that problem first :)

Cheers,
Anash P. Oommen,
AdWords API Advisor.

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


Re: dotnet api and sitelinks take 2

2011-11-16 Thread Paigey
Looks like the parsing of the campaignid is a bit buggy!
Using dotnet 4.0 and the latest version of the api so couldn't use
long.Parse.

Changed

string cid = "12345678"; //not real, just an example id
long campaignId = long.Parse(cid);

To

string cid = "12345678"; //not real, just an example id
long campaignId = Int64.Parse(cid);

and that seems to have fixed it to a point but still get an occasional
error thrown up by the api saying the IDENTITY ID wasn't found when
removing sitelinks.

If anyone knows a better way to parse a string as long that would be
great otherwise will do some further testing to see if this keeps
happening!


On Nov 14, 6:05 pm, Paigey  wrote:
> 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  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;
> >                    

Re: dotnet api and sitelinks take 2

2011-11-14 Thread Paigey
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  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 && ret