My favorites | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php

// Copyright 2005, Google Inc. All rights reserved.

/**
* sample code to generate ad code snippet of an existing account through Adsense API
*/

require_once('lib/nusoap.php');
require_once('common.php');

$server = 'https://sandbox.google.com';
// Comment out the line above and uncomment the line below to use
// the production API server
// $server = 'https://www.google.com';
$namespace = 'http://www.google.com/api/adsense/v3';

// Set up the authentication headers
$email = "<developer_email>REPLACE WITH DEVELOPER EMAIL</developer_email>";
$password = "<developer_password>REPLACE WITH DEVELOPER PASSWORD</developer_password>";
$client_id = "<client_id>REPLACE WITH CLIENT ID</client_id>";

$header = $email . $password . $client_id;

// creating soap client
$wsdl = $server . '/api/adsense/v3/AccountService?wsdl';
$client = new soapclient($wsdl, true);
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
$client->soap_defencoding = 'UTF-8';

// Set the headers; they are needed for authentication
$client->setHeaders($header);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

// setting the parameter
$param = "<ns1:getSyndicationService xmlns:ns1=\"$namespace\"><synServiceType><value>ContentAds</value></synServiceType></ns1:getSyndicationService>";

// invoke web service
showCall('getSyndicationService', $param);
$response = $client->call('getSyndicationService', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

// get back the response
$response = $response['return'];
$synServiceId = $response['id'];
showSynServiceId($synServiceId);



// showing the soap
showRequestResponse($client);


// setup client soap for another webservice
$wsdl = $server . '/api/adsense/v3/AdSenseForContentService?wsdl';
$client = new soapclient($wsdl, true);
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
$client->soap_defencoding = 'UTF-8';

// Set the headers; they are needed for authentication
$client->setHeaders($header);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

// setting up adstyle parameter
$ads_param = '<adStyle>';
$ads_param .= "<name>demoStyle</name>";
$ads_param .= '<borderColor>#0000FF</borderColor>';
$ads_param .= '<backgroundColor>#FFFFFF</backgroundColor>';
$ads_param .= '<titleColor>#FF0000</titleColor>';
$ads_param .= '<textColor>#00FF00</textColor>';
$ads_param .= '<urlColor>#FFFF00</urlColor>';
$ads_param .= '</adStyle>';

// setting up parameter
$param = '<synServiceId>'.$synServiceId.'</synServiceId>';
$param .= $ads_param;
$param .= '<adUnitType><value>TextOnly</value></adUnitType>';
$param .= '<layout><value>728x90</value></layout>';
$param .= '<alternate>#FFFFFF</alternate>';
$param .= '<isFramedPage type="xsd:boolean">false</isFramedPage>';
$param .= '<channelName xsi:nil="true"/>';
$param .= '<cornerStyles><value>DEFAULT</value></cornerStyles>';

$param = "<ns1:generateAdCode xmlns:ns1=\"$namespace\">" . $param . "</ns1:generateAdCode>";

// invoke the web service
showCall('generateAdCode', $param);
$response = $client->call('generateAdCode', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

$response = $response['return'];
$snippet = $response;
showSnippet($snippet);

// showing the soap
showRequestResponse($client);

?>
Show details Hide details

Change log

r97 by api.wes on Jan 23, 2009   Diff
Updated AssociateAccount.php to
concatenate params properly.  Updated
spacing in other files.
Go to: 
Project members, sign in to write a code review

Older revisions

r95 by api.wes on Aug 19, 2008   Diff
created v3 subdir in samplecode.
r94 by api.wes on Aug 19, 2008   Diff
Added samplecode to project.
All revisions of this file

File info

Size: 3664 bytes, 138 lines