Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit b03b821

Browse files
authored
Merge pull request #207 from BingAds/v13.0.24
v13.0.24
2 parents 7d0b9d2 + 695bec1 commit b03b821

File tree

387 files changed

+6501
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

387 files changed

+6501
-217
lines changed

samples/V13/CampaignManagementExampleHelper.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Microsoft\BingAds\Samples\V13;
44

5-
require_once __DIR__ . "/../vendor/autoload.php";
5+
require_once __DIR__ . "/../../vendor/autoload.php";
66

77
use SoapVar;
88
use SoapFault;
@@ -33,6 +33,7 @@
3333
use Microsoft\BingAds\V13\CampaignManagement\ApplyOfflineConversionAdjustmentsRequest;
3434
use Microsoft\BingAds\V13\CampaignManagement\ApplyOfflineConversionsRequest;
3535
use Microsoft\BingAds\V13\CampaignManagement\ApplyProductPartitionActionsRequest;
36+
use Microsoft\BingAds\V13\CampaignManagement\CreateResponsiveAdRecommendationRequest;
3637
use Microsoft\BingAds\V13\CampaignManagement\DeleteAdExtensionsRequest;
3738
use Microsoft\BingAds\V13\CampaignManagement\DeleteAdExtensionsAssociationsRequest;
3839
use Microsoft\BingAds\V13\CampaignManagement\DeleteAdGroupCriterionsRequest;
@@ -451,6 +452,18 @@ static function ApplyProductPartitionActions(
451452

452453
return $GLOBALS['CampaignManagementProxy']->GetService()->ApplyProductPartitionActions($request);
453454
}
455+
static function CreateResponsiveAdRecommendation(
456+
$finalUrls)
457+
{
458+
$GLOBALS['CampaignManagementProxy']->SetAuthorizationData($GLOBALS['AuthorizationData']);
459+
$GLOBALS['Proxy'] = $GLOBALS['CampaignManagementProxy'];
460+
461+
$request = new CreateResponsiveAdRecommendationRequest();
462+
463+
$request->FinalUrls = $finalUrls;
464+
465+
return $GLOBALS['CampaignManagementProxy']->GetService()->CreateResponsiveAdRecommendation($request);
466+
}
454467
static function DeleteAdExtensions(
455468
$accountId,
456469
$adExtensionIds)
+291
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
<?php
2+
3+
namespace Microsoft\BingAds\Samples\V13;
4+
5+
// For more information about installing and using the Bing Ads PHP SDK,
6+
// see https://go.microsoft.com/fwlink/?linkid=838593.
7+
8+
//require_once __DIR__ . "/../vendor/autoload.php";
9+
10+
include __DIR__ . "/AuthHelper.php";
11+
include __DIR__ . "/CampaignManagementExampleHelper.php";
12+
13+
use SoapVar;
14+
use SoapFault;
15+
use Exception;
16+
17+
//Specify the Microsoft\BingAds\V13\CampaignManagement classes that will be used.
18+
use Microsoft\BingAds\V13\CampaignManagement\CallToAction;
19+
use Microsoft\BingAds\V13\CampaignManagement\LanguageName;
20+
use Microsoft\BingAds\V13\CampaignManagement\Campaign;
21+
use Microsoft\BingAds\V13\CampaignManagement\CampaignType;
22+
use Microsoft\BingAds\V13\CampaignManagement\BudgetLimitType;
23+
use Microsoft\BingAds\V13\CampaignManagement\AdGroup;
24+
use Microsoft\BingAds\V13\CampaignManagement\Bid;
25+
use Microsoft\BingAds\V13\CampaignManagement\Date;
26+
use Microsoft\BingAds\V13\CampaignManagement\ResponsiveAd;
27+
use Microsoft\BingAds\V13\CampaignManagement\ImageAsset;
28+
use Microsoft\BingAds\V13\CampaignManagement\TextAsset;
29+
30+
// Specify the Microsoft\BingAds\Auth classes that will be used.
31+
use Microsoft\BingAds\Auth\ServiceClient;
32+
use Microsoft\BingAds\Auth\ServiceClientType;
33+
34+
// Specify the Microsoft\BingAds\Samples classes that will be used.
35+
use Microsoft\BingAds\Samples\V13\AuthHelper;
36+
use Microsoft\BingAds\Samples\V13\CampaignManagementExampleHelper;
37+
38+
try
39+
{
40+
// Authenticate user credentials and set the account ID for the sample.
41+
AuthHelper::Authenticate();
42+
43+
// To run this example you'll need to provide a valid Ad Final URL
44+
$adFinalUrl = "https://contoso.com";
45+
// Set false to disable cleanup of created entities at the end
46+
$doCleanup = true;
47+
48+
print("-----\r\nCreateResponsiveAdRecommendation:\r\n");
49+
printf("-----\r\nGetting ad recommendation for URL %s ...\r\n", $adFinalUrl);
50+
$finalUrls = array($adFinalUrl);
51+
$responsiveAdRecommendationResponse = CampaignManagementExampleHelper::CreateResponsiveAdRecommendation(
52+
$finalUrls
53+
);
54+
$responsiveAd = $responsiveAdRecommendationResponse->ResponsiveAd;
55+
$newResponsiveAd = new ResponsiveAd();
56+
$newResponsiveAd->DevicePreference = $responsiveAd->DevicePreference;
57+
$newResponsiveAd->FinalUrls = $responsiveAd->FinalUrls;
58+
$newResponsiveAd->ForwardCompatibilityMap = $responsiveAd->ForwardCompatibilityMap;
59+
$newResponsiveAd->Headlines = $responsiveAd->Headlines;
60+
$newResponsiveAd->LongHeadlines = $responsiveAd->LongHeadlines;
61+
$newResponsiveAd->Descriptions = $responsiveAd->Descriptions;
62+
$newResponsiveAd->CallToAction = $responsiveAd->CallToAction;
63+
copyAssetLinks($newResponsiveAd->Headlines);
64+
copyAssetLinks($newResponsiveAd->LongHeadlines);
65+
copyAssetLinks($newResponsiveAd->Descriptions);
66+
$imageSuggestions = $responsiveAdRecommendationResponse->ImageSuggestions->AdRecommendationImageSuggestion;
67+
68+
// Select a few images from the suggested list. This example picks first 5 images
69+
$selectedImages = array_slice($imageSuggestions, 0, 5);
70+
71+
// Add selected images to your media library
72+
saveImages($selectedImages);
73+
74+
$images = array_map(function($x) {
75+
return $x->AssetLink;
76+
}, $selectedImages);
77+
$newResponsiveAd->Images = $images;
78+
79+
$newResponsiveAd->BusinessName = "Contoso";
80+
$newResponsiveAd->CallToActionLanguage = LanguageName::English;
81+
82+
// Create an Audience campaign with one ad group and a responsive ad
83+
$campaigns = array();
84+
$campaign = new Campaign();
85+
// CampaignType must be set for Audience campaigns
86+
$campaign->CampaignType = CampaignType::Audience;
87+
$campaign->Name = "Ad recommendation test " . $_SERVER['REQUEST_TIME'];
88+
$campaign->BudgetType = BudgetLimitType::DailyBudgetStandard;
89+
$campaign->DailyBudget = 50.00;
90+
// Languages must be set for Audience campaigns
91+
$campaign->Languages = array("All");
92+
$campaign->TimeZone = "PacificTimeUSCanadaTijuana";
93+
$campaigns[] = $campaign;
94+
95+
print("-----\r\nAddCampaigns:\r\n");
96+
$addCampaignsResponse = CampaignManagementExampleHelper::AddCampaigns(
97+
$GLOBALS['AuthorizationData']->AccountId,
98+
$campaigns
99+
);
100+
$campaignIds = $addCampaignsResponse->CampaignIds;
101+
print("CampaignIds:\r\n");
102+
CampaignManagementExampleHelper::OutputArrayOfLong($campaignIds);
103+
print("PartialErrors:\r\n");
104+
CampaignManagementExampleHelper::OutputArrayOfBatchError($addCampaignsResponse->PartialErrors);
105+
106+
// Add an ad group within the campaign.
107+
$adGroups = array();
108+
$adGroup = new AdGroup();
109+
$adGroup->CpcBid = new Bid();
110+
$adGroup->CpcBid->Amount = 0.09;
111+
date_default_timezone_set('UTC');
112+
$endDate = new Date();
113+
$endDate->Day = 31;
114+
$endDate->Month = 12;
115+
$endDate->Year = date("Y");
116+
$adGroup->EndDate = $endDate;
117+
$adGroup->Name = "Holiday Sale";
118+
$adGroup->StartDate = null;
119+
// Network cannot be set for ad groups in Audience campaigns
120+
$adGroup->Network = null;
121+
$adGroups[] = $adGroup;
122+
123+
print("-----\r\nAddAdGroups:\r\n");
124+
$addAdGroupsResponse = CampaignManagementExampleHelper::AddAdGroups(
125+
$campaignIds->long[0],
126+
$adGroups,
127+
null
128+
);
129+
$adGroupIds = $addAdGroupsResponse->AdGroupIds;
130+
print("AdGroupIds:\r\n");
131+
CampaignManagementExampleHelper::OutputArrayOfLong($adGroupIds);
132+
print("PartialErrors:\r\n");
133+
CampaignManagementExampleHelper::OutputArrayOfBatchError($addAdGroupsResponse->PartialErrors);
134+
135+
// Add a responsive ad within the ad group.
136+
$ads = array();
137+
$ads[] = new SoapVar(
138+
$newResponsiveAd,
139+
SOAP_ENC_OBJECT,
140+
'ResponsiveAd',
141+
$GLOBALS['CampaignManagementProxy']->GetNamespace()
142+
);
143+
144+
print("-----\r\nAddAds:\r\n");
145+
$addAdsResponse = CampaignManagementExampleHelper::AddAds(
146+
$adGroupIds->long[0],
147+
$ads
148+
);
149+
print("AdIds:\r\n");
150+
CampaignManagementExampleHelper::OutputArrayOfLong($addAdsResponse->AdIds);
151+
print("PartialErrors:\r\n");
152+
CampaignManagementExampleHelper::OutputArrayOfBatchError($addAdsResponse->PartialErrors);
153+
154+
if (!$doCleanup) {
155+
return;
156+
}
157+
else {
158+
// Delete the account's media.
159+
print("-----\r\nDeleteMedia:\r\n");
160+
$mediaIds = array_map(function($x) {
161+
return $x->Asset->enc_value->Id;
162+
}, $newResponsiveAd->Images);
163+
CampaignManagementExampleHelper::DeleteMedia(
164+
$GLOBALS['AuthorizationData']->AccountId,
165+
$mediaIds
166+
);
167+
168+
foreach ($mediaIds as $id)
169+
{
170+
printf("Deleted Media Id %s\r\n", $id);
171+
}
172+
173+
// Delete the campaign and everything it contains e.g., ad groups and ads.
174+
175+
print("-----\r\nDeleteCampaigns:\r\n");
176+
CampaignManagementExampleHelper::DeleteCampaigns(
177+
$GLOBALS['AuthorizationData']->AccountId,
178+
array($campaignIds->long[0])
179+
);
180+
printf("Deleted CampaignId %s\r\n", $campaignIds->long[0]);
181+
}
182+
}
183+
catch (SoapFault $e)
184+
{
185+
printf("-----\r\nFault Code: %s\r\nFault String: %s\r\nFault Detail: \r\n", $e->faultcode, $e->faultstring);
186+
var_dump($e->detail);
187+
print "-----\r\nLast SOAP request/response:\r\n";
188+
print $GLOBALS['Proxy']->GetWsdl() . "\r\n";
189+
print $GLOBALS['Proxy']->GetService()->__getLastRequest()."\r\n";
190+
print $GLOBALS['Proxy']->GetService()->__getLastResponse()."\r\n";
191+
}
192+
catch (Exception $e)
193+
{
194+
// Ignore fault exceptions that we already caught.
195+
if ($e->getPrevious())
196+
{ ; }
197+
else
198+
{
199+
print $e->getCode()." ".$e->getMessage()."\r\n";
200+
print $e->getTraceAsString()."\r\n";
201+
}
202+
}
203+
204+
function copyAssetLinks($assetLinks) {
205+
for ($i = 0; $i < count($assetLinks->AssetLink); $i++) {
206+
$textAsset = new TextAsset();
207+
foreach ($assetLinks->AssetLink[$i]->Asset as $key => $value) {
208+
$textAsset->$key = $value;
209+
}
210+
$assetLinks->AssetLink[$i]->Asset = new SoapVar(
211+
$textAsset,
212+
SOAP_ENC_OBJECT,
213+
'TextAsset',
214+
$GLOBALS['CampaignManagementProxy']->GetNamespace()
215+
);
216+
}
217+
}
218+
219+
function saveImages($imageSuggestions) {
220+
$mediaToAdd = array();
221+
222+
foreach ($imageSuggestions as $imageSuggestion) {
223+
$image = $imageSuggestion->Image;
224+
225+
$imageBytes = downloadBytes($imageSuggestion->ImageUrl);
226+
$imageBase64 = base64_encode($imageBytes);
227+
228+
$image->Data = $imageBase64;
229+
230+
$encodedImage = new SoapVar(
231+
$image,
232+
SOAP_ENC_OBJECT,
233+
'Image',
234+
$GLOBALS['CampaignManagementProxy']->GetNamespace()
235+
);
236+
237+
$mediaToAdd[] = $encodedImage;
238+
}
239+
240+
$addMediaResponse = CampaignManagementExampleHelper::AddMedia(
241+
$GLOBALS['AuthorizationData']->AccountId,
242+
$mediaToAdd
243+
);
244+
$mediaIds = $addMediaResponse->MediaIds;
245+
246+
for ($i = 0; $i < count($mediaIds->long); $i++) {
247+
$imageSuggestions[$i]->AssetLink->Asset->Id = $mediaIds->long[$i];
248+
$imageAsset = new ImageAsset();
249+
foreach ($imageSuggestions[$i]->AssetLink->Asset as $key => $value) {
250+
$imageAsset->$key = $value;
251+
}
252+
$imageSuggestions[$i]->AssetLink->Asset = new SoapVar(
253+
$imageAsset,
254+
SOAP_ENC_OBJECT,
255+
'ImageAsset',
256+
$GLOBALS['CampaignManagementProxy']->GetNamespace()
257+
);
258+
}
259+
}
260+
261+
function downloadBytes($url) {
262+
$outputStream = fopen('php://temp', 'r+');
263+
$buffer = '';
264+
$bufferSize = 4096;
265+
266+
$inputStream = fopen($url, 'rb');
267+
if ($inputStream === false) {
268+
throw new Exception("Unable to open URL: $url");
269+
}
270+
271+
try {
272+
while (!feof($inputStream)) {
273+
$buffer = fread($inputStream, $bufferSize);
274+
if ($buffer === false) {
275+
throw new Exception("Error reading from URL: $url");
276+
}
277+
fwrite($outputStream, $buffer);
278+
}
279+
280+
rewind($outputStream);
281+
$result = stream_get_contents($outputStream);
282+
if ($result === false) {
283+
throw new Exception("Error reading from temporary stream");
284+
}
285+
286+
return $result;
287+
} finally {
288+
fclose($inputStream);
289+
fclose($outputStream);
290+
}
291+
}

src/Auth/ServiceClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private function RefreshServiceProxy()
242242
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
243243
// Disable keep_alive to avoid 'Process open FD table is full'
244244
'keep_alive' => FALSE,
245-
'user_agent' => 'BingAdsSDKPHP ' . '13.0.23 ' . PHP_VERSION,
245+
'user_agent' => 'BingAdsSDKPHP ' . '13.0.24 ' . PHP_VERSION,
246246
'cache_wsdl' => 'WSDL_CACHE_NONE',
247247

248248
/**

src/V13/AdInsight/AgeEnum.php

+21
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,36 @@
33
namespace Microsoft\BingAds\V13\AdInsight;
44

55
{
6+
/**
7+
* Defines a value set of age ranges.
8+
* @link https:/learn.microsoft.com/advertising/ad-insight-service/ageenum?view=bingads-13 AgeEnum Value Set
9+
*
10+
* @used-by SelectionOfAgeEnum
11+
*/
612
final class AgeEnum
713
{
14+
/** The age range is unknown. */
815
const Unknown = 'Unknown';
16+
17+
/** The age range is 0 to 12. */
918
const ZeroToTwelve = 'ZeroToTwelve';
19+
20+
/** The age range is 13 to 17. */
1021
const ThirteenToSevenTeen = 'ThirteenToSevenTeen';
22+
23+
/** The age range is 18 to 24. */
1124
const EighteenToTwentyFour = 'EighteenToTwentyFour';
25+
26+
/** The age range is 25 to 34. */
1227
const TwentyFiveToThirtyFour = 'TwentyFiveToThirtyFour';
28+
29+
/** The age range is 35 to 49. */
1330
const ThirtyFiveToFourtyNine = 'ThirtyFiveToFourtyNine';
31+
32+
/** The age range is 50 to 64. */
1433
const FiftyToSixtyFour = 'FiftyToSixtyFour';
34+
35+
/** The age range is above 65. */
1536
const SixtyFiveAndAbove = 'SixtyFiveAndAbove';
1637
}
1738

src/V13/AdInsight/ApplyRecommendationEntity.php

+15
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
namespace Microsoft\BingAds\V13\AdInsight;
44

55
{
6+
/**
7+
* Apply a recommendation.
8+
* @link https:/learn.microsoft.com/advertising/ad-insight-service/applyrecommendationentity?view=bingads-13 ApplyRecommendationEntity Data Object
9+
*
10+
* @used-by ApplyRecommendationsRequest
11+
*/
612
final class ApplyRecommendationEntity
713
{
14+
/**
15+
* The identifier of the recommendation.
16+
* @var string
17+
*/
818
public $RecommendationId;
19+
20+
/**
21+
* The type of recommendation: ADD_BROAD_MATCH_KEYWORD, CAMPAIGN_BUDGET, KEYWORD, REMOVE_CONFLICTING_NEGATIVE_KEYWORD, RESPONSIVE_SEARCH_AD, or RESPONSIVE_SEARCH_AD_ASSET.
22+
* @var string
23+
*/
924
public $RecommendationType;
1025
}
1126

0 commit comments

Comments
 (0)