There really shouldn't be much concern over using ColdFusion. We have a number 
of scripts that run daily, hourly, etc., using the Google API, and have found 
it easiest to just create the SOAP document in the <CFXML> tag and then use 
<CFHTTP> to talk to Google.  Here is an example of code using the ReportService 
to pull back a previously requested report (with keys removed!).

<cfxml variable="variables.getreport" casesensitive="true">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<SOAP-ENV:Header>
<m:email xmlns:m="https://adwords.google.com/api/adwords/v6";>#q.login#</m:email>
<m:password 
xmlns:m="https://adwords.google.com/api/adwords/v6";>#q.password#</m:password>
<m:useragent 
xmlns:m="https://adwords.google.com/api/adwords/v6";>xxx</m:useragent>
<m:token xmlns:m="https://adwords.google.com/api/adwords/v6";>xxx</m:token>
<m:developerToken 
xmlns:m="https://adwords.google.com/api/adwords/v6";>xxx</m:developerToken>
<m:applicationToken 
xmlns:m="https://adwords.google.com/api/adwords/v6";>xxx</m:applicationToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:getGzipReportDownloadUrl xmlns:m="https://adwords.google.com/api/adwords/v6";>
<m:reportJobId>#q.report_id#</m:reportJobId>
</m:getGzipReportDownloadUrl> 
</SOAP-ENV:Body>                                
</SOAP-ENV:Envelope>
</cfxml>

<cfhttp url="https://adwords.google.com/api/adwords/v6/ReportService"; 
method="post">
<cfhttpparam name="SOAPAction" type="header" value=""/>
<cfhttpparam type="xml" value="#ToString(variables.getreport)#"/>
</cfhttp>

After this is when the fun begins.  Google will return HTTP error 500 for a 
number of problems, including bad login information.  When they do send back a 
200 response, you can still get XML documents that can be parsed with 
XMLparse(), but which might not have all of the XML elements you are expecting, 
depending on whether or not there is data on their end to download.  Rather 
than tell you "we don't have any data" they will just send back a skeleton XML 
doc, and leave the rest blank.  You end up using StructKeyExists() quite a bit. 
 I've also ended up putting TRY/CATCH around the block of code that tries to 
access the individual data elements, just to be safe.

Oh yea, sometimes they will just send you a 200 HTTP code, with a blank 
document.  They are not big into error codes: Sometimes they will send back in 
text (literally) an error message string.  My favorite is one that basically 
says "dude, I'm a little busy now, and don't know how to keep track of my 
backlogged work, so just come back later with your request and I'll see what I 
can do about it."  This makes parsing and handling the errors just a whole lot 
of fun.  The same is true using code such as the above example - after sending 
in the request for report creation, you have to wait for it to be ready.  If 
you try to get the report too soon, they tell you that with a text string 
(rather than an error code).  Also, if you wait too long, the report will 
expire and you have to reissue the report request.

Otherwise it's a breeze.  Oh yea, I noticed in your example that you were using 
the V2 API.  I'm surprised that you got any response at all.  They stopped 
responding to my V4-formatted SOAP requests about a week or two ago.  Right now 
it's V5 or V6 only.

Here is the link to their documentation, in case you don't already have it:
http://www.google.com/apis/adwords/developer/Keyword.html

Good luck!
Reed


>Does anyone have any experience with Google Adwords API service? I trying to
>figure out some of the sample code provided on the Goggle Groups and in the
>Documentation, so far I have not been able to get any of the examples to
>work. I can make the connection to the service but beyond that, like
>modifying ad settings or adding keywords I can't seem to get anything
>working. 
> 
>If anyone here has any working examples or could provide some info that
>would be great. 
> 
>So far all I have that kind of works but generates an error is this:
> 
>-------------------------------------------------------
><cfset myEMail = "[EMAIL PROTECTED]"> 
><cfset myPassword = "xxxx"> 
><cfset myToken = "xxxx_xxxxxx"> 
><cfset myClient = "[EMAIL PROTECTED]"> 
><cfscript> 
>                getGoogleWSDL = 
>CreateObject("webservice","https://adwords.google.com/api/adwords/v2/Criteri
>onService?wsdl"); 
> 
>addSOAPRequestHeader(getGoogleWSDL,"https://adwords.google.com/api/adwords/v
>2","email",myEMail); 
> 
>addSOAPRequestHeader(getGoogleWSDL,"https://adwords.google.com/api/adwords/v
>2","password",myPassword); 
> 
>addSOAPRequestHeader(getGoogleWSDL,"https://adwords.google.com/api/adwords/v
>2","token",myToken); 
> 
>addSOAPRequestHeader(getGoogleWSDL,"https://adwords.google.com/api/adwords/v
>2","useragent","ColdFusion AdWords"); 
> 
>addSOAPRequestHeader(getGoogleWSDL,"https://adwords.google.com/api/adwords/v
>2","clientEmail",myClient); 
> 
> 
>                aKeywordRequest = structnew(); 
>                        aKeywordRequest.adGroupId="-- AD_ID goes here --"; 
>                aKeywordRequest.type="broad"; 
>                        aKeywordRequest.text="music"; 
> 
> 
>                xmloutput = getGoogleWSDL.addCriteria(aKeywordRequest); 
></cfscript> 
> 
> 
><cfdump var="#xmloutput#">
>------------------------------------------------------
> 
>Neal Bailey

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:260226
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to