Got Ads?
2/04/2005
  Call Google AdWords API from JavaScript

Here's a test program I wrote. You can indeed call the Google AdWordsAPI from JavaScript...


function postData(Url, Data, Action) {
  var oHttpReq = new ActiveXObject("Msxml2.XMLHTTP.4.0");
  oHttpReq.open("POST", Url, false);
  oHttpReq.setRequestHeader("Man", "POST" + Url + "HTTP/1.1");
  oHttpReq.setRequestHeader("MessageType", "CALL");
  oHttpReq.setRequestHeader("Content-Type", "text/xml");
  oHttpReq.setRequestHeader("SOAPACtion", Action);
  oHttpReq.send(Data);
  return oHttpReq;
}

function main() {
  var sUrl = "https://adwords.google.com/api/adwords/v2";
  var sData = ' <soap:Envelope  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://adwords.google.com/api/adwords/v2">
<soap:Header>
<email>EMAIL HERE</email>
<password>YOUR PASSWORD</password>
<useragent>XXX</useragent>
<token>YOUR TOKEN</token>
<clientEmail></clientEmail>
</soap:Header>
<soap:Body>
<getOperationCount>
<startdate>2005-01-02T23:59:59</startdate><enddate>2005-02-02T23:59:59</enddate>
</getOperationCount></soap:Body></soap:Envelope>';

  var oResponse = postData(sUrl, sData, "getOperationCount");
  if (oResponse.status == 200) {
    WScript.echo(oResponse.responseText);    
  } else {
    WScript.echo("Could not retrieve data:\n" + oResponse.statusText + " (" + oResponse.status + ")");     
  }
  oHttpReq = null;
}

main();

 




<< Home

Subscribe to GotAds?



Links



Recent Posts

Call Google AdWords API from JavaScript


Archives

February 2005 /  March 2005 /  April 2005 /  May 2005 /  June 2005 /  July 2005 /  August 2005 /  September 2005 /  October 2005 /  November 2005 /  December 2005 /  January 2006 /  February 2006 /  March 2006 /  April 2006 /  May 2006 /  June 2006 /  July 2006 /  August 2006 /  September 2006 /  October 2006 /  November 2006 /  December 2006 /  January 2007 /  February 2007 /  March 2007 /  April 2007 /  May 2007 /  June 2007 /  July 2007 /  August 2007 /  September 2007 /  October 2007 /  November 2007 /  December 2007 /  January 2008 /  February 2008 /  March 2008 /  April 2008 /  May 2008 /  June 2008 /  July 2008 /  August 2008 /  September 2008 /  November 2008 /  December 2008 /  January 2009 /  March 2009 /