Board index » delphi » is possible to access AdWords API via D6?

is possible to access AdWords API via D6?


2006-06-23 04:03:35 PM
delphi201
Can anybody say if it is possible to use the services built into Delphi 6 to access the Google AdWords API?
I'm able to import the WSDL, but the resulting classes are all missing headers required by the API and I am not sure where they're supposed to originate. I really hate having to shell out for a 3rd party lib just because I can not get proper docs on what's already available with Delphi.
Alternatively, D2006 upgrade is cheaper then one 3rd party lib and not much more than the other. So, if anybody can say if D2006 will work, that would be helpful.
(For more info on the AdWords API, go to: www.google.com/apis/adwords/index.html)
Thanks!
-David
digloo2 (at) gmail (dot com)
 
 

Re:is possible to access AdWords API via D6?

DavidS writes:
Quote
Can anybody say if it is possible to use the services built into Delphi 6 to
access the Google AdWords API?

I'm able to import the WSDL, but the resulting classes are all
missing headers required by the API and I am not sure where they're
supposed to originate. I really hate having to shell out for a 3rd
party lib just because I can not get proper docs on what's already
available with Delphi.
David,
Here goes. I finally got some of it to work, but it needed a few
additions to the imported file.
In the imported file:
In the interface section add the following code:
TAdWordsHeaderStringBase = class( TSoapHeader)
private
FString : string;
published
property Text : string read FString write FString;
end;
TAdWordsHeaderLongBase = class( TSoapHeader)
private
FString : longint; //don't ask. Laziness
published
property Text : longint read FString write FString;
end;
email = class( TAdWordsHeaderStringBase ) end;
password = class( TAdWordsHeaderStringBase ) end;
useragent = class( TAdWordsHeaderStringBase ) end;
token = class( TAdWordsHeaderStringBase ) end;
clientEmail = class( TAdWordsHeaderStringBase ) end;
responseTime = class( TAdWordsHeaderStringBase ) end;
operations = class( TAdWordsHeaderLongBase ) end;
units = class( TAdWordsHeaderLongBase ) end;
In the Initialization section add this code:
RemClassRegistry.RegisterXSClass(email,
'https://adwords.google.com/api/adwords/v4', 'email');
RemClassRegistry.RegisterSerializeOptions(email,
[xoSimpleTypeWrapper]);
RemClassRegistry.RegisterXSClass(password,
'https://adwords.google.com/api/adwords/v4', 'password');
RemClassRegistry.RegisterSerializeOptions(password,
[xoSimpleTypeWrapper]);
RemClassRegistry.RegisterXSClass(token,
'https://adwords.google.com/api/adwords/v4', 'token');
RemClassRegistry.RegisterSerializeOptions(token,
[xoSimpleTypeWrapper]);
RemClassRegistry.RegisterXSClass(useragent,
'https://adwords.google.com/api/adwords/v4', 'useragent');
RemClassRegistry.RegisterSerializeOptions(useragent,
[xoSimpleTypeWrapper]);
(note: all sorts of wrapping will happen)
An example of calling this is:'
var
service : CampaignService ;
myUseragent, myPassword, myToken, myEmail : string;
Headers : ISoapHeaders;
ua : useragent;
em : email;
pwd : password;
tok : token;
CampaignList : getAllAdWordsCampaignsResponse;
i : integer;
c : Campaign;
s : getAllAdWordsCampaigns;
begin
service := GetCampaignService(False, '', HTTPRIO1);
// set headers
myUseragent := 'Deepak = Delphi Get Campaign Test';
myEmail := 'XXXX@XXXXX.COM"
myPassword := 'secret';
myToken := 'your token goes here';
Headers := service as ISoapHeaders;
ua := useragent.Create();
ua.Text := myUseragent;
Headers.Send(ua);
em := email.Create();
em.Text := myEmail;
Headers.Send(em);
pwd := password.Create();
pwd.Text := myPassword;
Headers.Send(pwd);
tok := token.Create();
tok.Text := myToken;
Headers.Send(tok);
// retrieve all campaigns and display the data
s := getAllAdWordsCampaigns.Create;
s.dummy := 0;
CampaignList := service.getAllAdWordsCampaigns(s);
for i := 0 to Length(CampaignList.getAllAdWordsCampaignsReturn)-1 do
begin
c := CampaignList.CampaignArray[i];
Memo1.Lines.add('Campaign name: ' + c.name);
Memo1.Lines.add('Campaign daily budget: ' + IntToSt(c.dailyBudget));
Memo1.Lines.add('Campaign status: ' + IntToStr(Ord(c.status)));
end;
end;
That help any?
--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
 

Re:is possible to access AdWords API via D6?

"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes:
Quote
DavidS writes:

>Can anybody say if it is possible to use the services built into Delphi 6 to
>access the Google AdWords API?
>
>. . .

David,

Here goes. I finally got some of it to work, but it needed a few
additions to the imported file.

In the imported file:
In the interface section add the following code:

TAdWordsHeaderStringBase = class( TSoapHeader)
private
FString : string;
published
property Text : string read FString write FString;
end;
TAdWordsHeaderLongBase = class( TSoapHeader)
private
FString : longint; //don't ask. Laziness
published
property Text : longint read FString write FString;
end;

email = class( TAdWordsHeaderStringBase ) end;
password = class( TAdWordsHeaderStringBase ) end;
useragent = class( TAdWordsHeaderStringBase ) end;
token = class( TAdWordsHeaderStringBase ) end;
clientEmail = class( TAdWordsHeaderStringBase ) end;
responseTime = class( TAdWordsHeaderStringBase ) end;
operations = class( TAdWordsHeaderLongBase ) end;
units = class( TAdWordsHeaderLongBase ) end;

. . .

That help any?

--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
Wow, this is terrific, Deepak! Thanks! I will give this a try.
(I dug around for quite a while, but couldn't figure out how to
inject those header fields.)
Just one odd question: the "standard" is to prefix objects with
a 'T'. Why are none of the objects generated by the WSDL
importer defined this way?
It's kinda strange defining fields like:
email_fld : email;
token_fld : token;
the_campaign : campaign;
Any idea what's behind that?
-David
 

Re:is possible to access AdWords API via D6?

"Deepak Shenoy (TeamB)" <XXXX@XXXXX.COM>writes:
Quote
DavidS writes:


David,

Here goes. I finally got some of it to work, but it needed a few
additions to the imported file.

In the imported file:
In the interface section add the following code:

TAdWordsHeaderStringBase = class( TSoapHeader)
private
FString : string;
published

. . .

That help any?

--
Deepak Shenoy (TeamB)
shenoyatwork.blogspot.com
Where is 'TSoapHeader' supposed to be defined?
There is no TSoapHeaders class defined anywhere that I can find. Nor an ISoapHeaders.
I'll keep digging, but it is not obvious.
Thanks
-David