7 messages in com.googlegroups.adwords-apiRe: PHP implementation not working| Subject: | Re: PHP implementation not working![]() |
|---|---|
| From: | crazylane (craz...@gmail.com) |
| Date: | 05/23/2005 11:57:58 PM |
| List: | com.googlegroups.adwords-api |
I think the problem is if your running php5, php5 handles arrays a little different.
I had to change this $campaign["id"] to $campaign ["addCampaignReturn"]["id"] for every return.
It helped me to print_r the return arrays and allso you can see all the parameters of each wsdl by just putting it in your browser.
Hope this helps.
<? require_once('lib/nusoap.php');
/* This sample program illustrates how to: -- create a campaign -- add an AdGroup to it, -- add keywords to the AdGroup -- add creatives to the Ad Group.
This program uses nusoap.php to handle the SOAP interactions. */
// Set up the authentication headers for logging in to the AdWords account $email = "<email>xx@xxx</email>"; $password = "<password>xxx</password>"; $userAgent = "<useragent>xxx -- PHP Campaign Demo</useragent>"; $token = "<token>xxxx</token>"; $header = $email . $password . $userAgent . $token;
// Connect to the CampaignService wsdl $campaignwsdl="https://adwords.google.com/api/adwords/v2/CampaignService?wsdl"; $campaignclient=new soapclient($campaignwsdl, 'wsdl');
// Connect to the AdGroupService wsdl $adgroupwsdl="https://adwords.google.com/api/adwords/v2/AdGroupService?wsdl"; $adgroupclient=new soapclient($adgroupwsdl, 'wsdl');
// Connect to the KeywordService wsdl $keywordwsdl="https://adwords.google.com/api/adwords/v2/KeywordService?wsdl"; $keywordclient=new soapclient($keywordwsdl, 'wsdl');
// Connect to the CreativeService wsdl $creativewsdl="https://adwords.google.com/api/adwords/v2/CreativeService?wsdl"; $creativeclient=new soapclient($creativewsdl, 'wsdl');
// Set the headers for each client; they are needed for authentication $campaignclient->setHeaders($header); $adgroupclient->setHeaders($header); $keywordclient->setHeaders($header); $creativeclient->setHeaders($header);
// Create a new campaign with some ad groups // First create the campaign so we can get its id $campaign = "<campaign>foo</campaign>";
// Campaign name is optional // $campaignName="<name>campaign one</name>";
// Daily budget is required $dailyBudget = "<dailyBudget>2000000</dailyBudget>";
// Language targeting is optional $languages = "<languageTargeting><languages>en</languages><languages>fr</languages></languageTargeting>";
// Geotargeting is optional. // You can target at cities *or* regions *or* countries. // Here we target at the countries France and Great Britain. $geotargets = "<geoTargeting><countries>FR</countries><countries>GB</countries></geoTargeting>";
$campaignparams = "<campaign> $dailyBudget $languages $geotargets</campaign>";
// Construct the XML string for the parameters // It's a nusoap thing that the param string needs to include the operation name too. // Specifying xmlns (xml namespace) is optional since AdWords API web services can use // the default xml namespace // $campaignparamsxml="<addCampaign xmlns='https://adwords.google.com/api/adwords/v2'> $campaignparams </addCampaign>"; $campaignparamsxml="<addCampaign> $campaignparams </addCampaign>";
// Make the request to add the campaign $campaign= $campaignclient->call("addCampaign", $campaignparamsxml); print_r($campaign); /* handle any SOAP faults. */ if ($campaignclient->fault) { showMyErrors($campaignclient); return; }
// If we get this far, the campaign was created. // Each field of the campaign, such as dailyBudget or Id, is a key of the returned array. $campaignId = $campaign ["addCampaignReturn"]["id"]; echo $campaign ["addCampaignReturn"]["id"]; echo "<P>The id of the new campaign is " . $campaign["addCampaignReturn"]["id"] . "and the name is " . $campaign["addCampaignReturn"]["name"];
// Add an AdGroup. // maxCpc and campaignId are the required parameters. $maxcpc = "<maxCpc>50000</maxCpc>"; $adgroupParams = "<newdata> $maxcpc $campaignId </newdata>"; $campaignidparam = "<campaignID> $campaignId </campaignID>"; $adgroupParamsxml = "<addAdGroup> $campaignidparam $adgroupParams </addAdGroup>";
// Make the request to add the adgroup $adgroup= $adgroupclient->call("addAdGroup", $adgroupParamsxml); print_r($adgroup); /* handle any SOAP faults. */ if ($adgroupclient->fault) { showMyErrors($adgroupclient); return; }
// If we get this far, the Ad Group was created
echo "<P>Ad Group " . $adgroup["addAdGroupReturn"]["name"] . "was created successfully"; $adgroupid = "<adGroupId>" . $adgroup["addAdGroupReturn"]["id"] . "</adGroupId>";
// Now add some keywords $keyword1 ="<newKeywords><text>springers</text><type>Broad</type></newKeywords>"; $keyword2 ="<newKeywords><text>spaniels</text><type>Broad</type></newKeywords>"; $keyword3 ="<newKeywords><text>english springer spaniel</text><type>Broad</type></newKeywords>";
$keywordlist = "$keyword1 $keyword2 $keyword3";
// The input args to addKeywordList are (adgroupid, keywordArray). $keywordparamsxml = "<addKeywordList> $adgroupid $keywordlist </addKeywordList>";
// Make the request to add the keywords $keywordarray = $keywordclient->call("addKeywordList", $keywordparamsxml);
/* handle any SOAP faults. */ if ($keywordclient->fault) { showMyErrors($keywordclient); return; }
// If we get this far, the keywords were created
// Add two creatives. // For the sake of brevity in the example, the only difference between // the two creatives is in description2
$headline = "<headline>Rescue Springer Spaniels</headline>"; $description1 = "<description1>Save a Springer from the shelter.</description1>"; $description2a = "<description2>Get a friend for life.</description2>"; $description2b = "<description2>Get a faithful friend.</description2>"; $displayUrl = "<displayUrl>www.saveSpringerSpaniels.dog</displayUrl>"; $destinationUrl = "<destinationUrl>http://www.saveSpringerSpaneils.dog</destinationUrl>";
// Add a single creative /* $creative1="<creative>$adgroupid $headline $description1 $description2a $destinationUrl $displayUrl </creative>"; $creativeparamsxml = "<addCreative> $creative1 </addCreative>"; $creativesarray = $creativeclient->call("addCreative", $creativeparamsxml); */
// Add multiple creatives $creative1="<creative>$adgroupid $headline $description1 $description2a $destinationUrl $displayUrl </creative>"; $creative2="<creative>$adgroupid $headline $description1 $description2b $destinationUrl $displayUrl </creative>"; $creativeparamsxml = "<addCreativeList> $creative1 $creative2</addCreativeList>";
// Make the request to add the creatives $creativesarray = $creativeclient->call("addCreativeList", $creativeparamsxml);
/* handle any SOAP faults. */ if ($creativeclient->fault) { showMyErrors($creativeclient); return; }
function showMyErrors ($client) { echo "<P>FAULT: {$client->fault}"; echo "<P>Code: {$client->faultcode}"; echo "<P>String: {$client->faultstring}"; echo "<P>Detail: {$client->faultdetail}"; } ?>




