My script :
*******************************************************************************
******************************Begin
script***********************************
*******************************************************************************
require_once 'src/Google/Api/Ads/AdWords/v201306/AdGroupAdService.php';
define("ADWORDS_API_VERSION", "v201306");
// Production API
//define("ADWORDS_API_SERVER", "https://adwords.google.com");
// Sandbox API
define("ADWORDS_API_SERVER", "https://adwords.google.com");
define("ADWORDS_API_NAMESPACE", "https://adwords.google.com/api/adwords/cm/"
. ADWORDS_API_VERSION);
define("ADWORDS_API_ADGROUPADSERVICE", ADWORDS_API_SERVER .
"/api/adwords/cm/" . ADWORDS_API_VERSION . "/AdGroupAdService");
// Your API Developer Token
define("ADWORDS_API_TOKEN", "******************************");
// The account that you want to download performace data from
$username = "[email protected]";
$password = "************))";
$customerId = "576-***-3559";
try {
// Get an auth token for the user
$url = "https://www.google.com/accounts/ClientLogin";
$params = array(
"accountType" => "GOOGLE",
"Email" => $username,
"Passwd" => $password,
"service" => "adwords",
"source" => "test"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
$pos = strpos($curlData, "Auth=");
if ($pos > -1) {
$auth = trim(substr($curlData, $pos + 5));
} else {
throw new Exception("You haven't supplied a valid username or
password for an existing Google account.");
}
// Create the headers needed to access the API
$headers = array(
"developerToken" => ADWORDS_API_TOKEN,
"userAgent" => "agence",
"clientCustomerId" => $customerId,
"authToken" => $auth
);
// Encode the headers
$encodedHeaders = new SoapHeader(ADWORDS_API_NAMESPACE,
"RequestHeader", $headers, false);
$options = array(
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'encoding' => 'utf-8');
// Create the SOAP client
$client = new SoapClient(ADWORDS_API_ADGROUPADSERVICE . "?wsdl",
$options);
$client->__setSoapHeaders($encodedHeaders);
$adGroupId = '8424820921';
$numAds = 5;
$operations = array();
// for ($i = 0; $i < $numAds; $i++) {
// Create text ad.
$textAd = new TextAd();
$textAd->headline = 'Cruise';
$textAd->description1 = 'Visit';
$textAd->description2 = 'Low-gravity';
$textAd->displayUrl = 'www.example.com';
$textAd->url = 'http://www.example.com';
$textAd->AdType = "TextAd";
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->adGroupId = $adGroupId;
$adGroupAd->ad = $textAd;
// Set additional settings (optional).
$adGroupAd->status = 'PAUSED';
// Create operation.
$operation = new AdGroupAdOperation();
$operation->operand = $adGroupAd;
$operation->operator = 'ADD';
$operations[] = $operation;
// }
// Make the mutate request.
$result = $client->mutate($operations);
// Display results.
foreach ($result->value as $adGroupAd) {
printf("Text ad with headline '%s' and ID '%s' was added.\n",
$adGroupAd->ad->headline, $adGroupAd->ad->id);
}
} catch (Exception $e) {
print_r($e);
if (isset($client)) {
print $client->__getLastRequest() . "\n";
print $client->__getLastResponse() . "\n";
}
}
**********************************END SCRIPT*******************************
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.