Related Categories: Web Dev

This weekend I was having trouble connecting to the Google Adsense API.  I was certain my headers were set up correctly, and yet google responded that my headers didn't exist.  Turns out I had my namespace incorrect.  Once that was rectified the API was easy to get at.  I haven't played with the data all that much, but they sure make it easy thus far.

On a side note, it is disappointing that they don't have sample CF code.  If I write enough using the API I will submit it to them.

Here is a quick example of getting the adsense services a publisher is subscribed to.

 

<cfscript>
myvar = CreateObject("webservice", "https://sandbox.google.com/api/adsense/v2/AccountService?wsdl");

// these is sandbox developer account information for testing
AddSOAPRequestHeader(myvar, "
http://www.google.com/api/adsense/v2", "developer_email", "sandboxdeveloper@google.com");
AddSOAPRequestHeader(myvar, "http://www.google.com/api/adsense/v2", "developer_password", "devpass");
AddSOAPRequestHeader(myvar, "
http://www.google.com/api/adsense/v2", "client_id", "ca-pub-8230466390320431");

</cfscript>
<!--- call function to get services this publisher has subscribed to --->
<cfset servicelist = myvar.getAllSyndicationServices(1)>

<cfset mylength = arraylen(servicelist)>
<cfoutput>
<cfloop from="1" to="#mylength#" index="i">
#servicelist[i].id# #servicelist[i].type#
<br />
</cfloop>
</cfoutput>

 

Resulting in:

ca-pub-8230466390320431 ContentAds
partner-pub-8230466390320431 SearchAds
ca-ref-pub-8230466390320431 ReferralAds

 


Like this entry? Subscribe to my blog.

Comments (moderation on)

Hi there,

I'm curious to know if you've played around with any of the other Adsense API's, I've been fighting with these things for a week now and just not sure where i'm going wrong... in particular the aggregateReports .
# Posted By colin | 7/5/07 3:39 AM
No, I haven't yet. But I know Ray Camden has done some. You may want to check www.RiaForge.org for any google api related projects.
# Posted By Joshua | 7/5/07 9:08 AM

Sponsors


Savvy Content Manager