How to Submit an Ad Group for Approval in PHP (V5)
We will release PHP samples in V5 to MSDN by May 2008. In the interim, we'll use this site to release PHP samples in V5.
Ad groups are submitted for approval by calling the SubmitAdGroupForApproval service operation. The approval process includes several automated checks for relevance and adherence to Editorial Guidelines. Generally, an ad is approved or disapproved immediately after being submitted. In some cases, however, the process might take up to five business days.
The following PHP example shows how to submit an ad group for approval by using SubmitAdGroupForApproval
. This example assumes that you have already created your ads and keywords. This example also assumes that you have already determined which ad group ID will be submitted for approval; you must substitute your ad group ID for the $adGroupId
variable that is assigned 50786905
in the following code.
Thanks,
Walter Poupore
Lead Programming Writer
Microsoft adCenter API
<?php
// This program requires the following PHP extensions:
// php_soap.dll
// php_openssl.dll
// To ensure that a cached WSDL is not being used,
// disable WSDL caching.
ini_set("soap.wsdl_cache_enabled", "0");
try
{
$adGroupId = 50786905; //Application-specific value.
// Use either the sandbox or production URI.
// This example is for the sandbox URI.
$URI =
"https://sandboxapi.adcenter.microsoft.com/api/advertiser/v5/";
// The following commented-out line contains the production URI.
//$URI = "https://adcenterapi.microsoft.com/api/advertiser/v5/";
// The Microsoft adCenter API namespace.
$xmlns = "https://adcenter.microsoft.com/api/advertiser/v5";
// The proxy for the Campaign Management Web service.
$campaignProxy =
$URI . "CampaignManagement/CampaignManagementService.svc?wsdl";
// The name of the service operation that will be called.
$action = "SubmitAdGroupForApproval";
// The user name, password, and developer token are
// expected to be passed in as command-line
// arguments.
// $argv[0] is the PHP file name.
// $argv[1] is the user name.
// $argv[2] is the password.
// $argv[3] is the developer token.
if ($argc !=4)
{
printf("Usage:\n");
printf(
"php file.php username password devtoken\n");
exit(0);
}
$username = $argv[1];
$password = $argv[2];
$developerTokenValue = $argv[3];
$applicationTokenValue="";
// Assign the credentials to the classes
// that are used by the SOAP headers.
$userCredentials=new UserCredentials();
$userCredentials->Username=$username;
$userCredentials->Password=$password;
$developerToken=new DeveloperToken();
$developerToken->Value=$developerTokenValue;
$applicationToken=new ApplicationToken();
$applicationToken->Value=$applicationTokenValue;
// Create the SOAP headers.
$headerApplicationToken =
new SoapHeader
(
$xmlns,
'ApplicationToken',
$applicationToken,
false
);
$headerDeveloperToken =
new SoapHeader
(
$xmlns,
'DeveloperToken',
$developerToken,
false
);
$headerUserCredentials =
new SoapHeader
(
$xmlns,
'UserCredentials',
$userCredentials,
false
);
// Create the SOAP input header array.
$inputHeaders = array
(
$headerApplicationToken,
$headerDeveloperToken,
$headerUserCredentials
);
// Create the SOAP client.
$opts = array('trace' => true);
$client = new SOAPClient($campaignProxy, $opts);
// Specify the parameters for the SOAP call.
$params = array
(
'AdGroupId' => $adGroupId
);
// Execute the SOAP call.
$result = $client->__soapCall
(
$action,
array( $action.'Request' => $params ),
null,
$inputHeaders,
$outputHeaders
);
print "$action succeeded with Tracking ID "
. $outputHeaders['ApiCallTrackingData']->TrackingId
. ".\n";
}
catch (Exception $e)
{
print "$action failed.\n";
// Display the fault code and the fault string.
print $e->faultcode . " " . $e->faultstring . ".\n";
print "TrackingID: " .
$e->detail->ApiFaultDetail->TrackingId . ".\n";
// Process operation errors.
if (isset(
$e->detail->ApiFaultDetail->OperationErrors->OperationError
))
{
if (is_array(
$e->detail->ApiFaultDetail->OperationErrors->OperationError
))
{
// An array of operation errors has been returned.
$obj =
$e->detail->ApiFaultDetail->OperationErrors->OperationError;
}
else
{
// A single operation error has been returned.
$obj = $e->detail->ApiFaultDetail->OperationErrors;
}
foreach ($obj as $operationError)
{
print "Operation error " .
$operationError->Code . " encountered. ";
print $operationError->Message . "\n";
}
}
}
// Definitions for classes that are used by the SOAP headers.
class ApplicationToken
{
public $Value;
}
class DeveloperToken
{
public $Value;
}
class UserCredentials
{
public $Password;
public $Username;
}
?>
Comments
- Anonymous
September 09, 2011
Thanks for posting this code.Me also one of the PHP programmer.This will more helpful to me. - Anonymous
November 03, 2011
Great Code! There is a great need for more in-depth reviews of certain products and technologies. Your tips are really helpful for anybody who wants to create reviews of any type. Great job - Anonymous
December 26, 2013
Sabase sasta HP, DELL, SONY, ASUS,laptops & computers.We are dealing in all types computers, laptops,data card ,dth,mobiles, computer peripherals, laptop peripherals,printer,LCD & LED sales and services For more information contact us on- +91-9214645678 or mail us on dr.computerclinic@gmail.com & log On www.sabsesastaindia.com sush04ngp1041