I'm not sure if I'm missing something with this, but I'm having problems generating ads with php and the v4.1 AdSense host.
I have all the access and refresh tokens up and running correctly, got the link set up between the user and all that set up. Now I'm trying to create ads for my test user.
You need to create ads first with the insert statement first, then get them with the generateAdCode function correct?
I copied this out of the example PHP code, doing a print_r it all seems to look correct.
$adUnit = new Google_AdUnit();
$adUnit->setName('Test 1');
$contentAdsSettings = new Google_AdUnitContentAdsSettings();
$backupOption = new Google_AdUnitContentAdsSettingsBackupOption();
$backupOption->setType('COLOR');
$backupOption->setColor('ffffff');
$contentAdsSettings->setBackupOption($backupOption);
$contentAdsSettings->setSize('SIZE_600_160'); //width then height
$contentAdsSettings->setType('TEXT');
$adUnit->setContentAdsSettings($contentAdsSettings);
$customStyle = new Google_AdStyle();
$colors = new Google_AdStyleColors();
$colors->setBackground('ffffff');
$colors->setBorder('000000');
$colors->setText('000000');
$colors->setTitle('000000');
$colors->setUrl('0000ff');
$customStyle->setColors($colors);
$customStyle->setCorners('SQUARE');
$font = new Google_AdStyleFont();
$font->setFamily('ACCOUNT_DEFAULT_FAMILY');
$font->setSize('ACCOUNT_DEFAULT_SIZE');
$customStyle->setFont($font);
$adUnit->setCustomStyle($customStyle);
This is the insert statement I'm running: ($pubID is the users pubID, $clientID is the app client ID for the project) (I think that is correct right?)
$result = $adsensehostService->accounts_adunits->insert($pubID, $clientID, $adUnit);
This is the error I'm getting
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/adsensehost/v4.1/accounts/pub-25716040XXXXXXXXX/adclients/74197XXXXXXXXXX.apps.googleusercontent.com/adunits?key=AIzaSyDCXXXXXXXXXvkxQBU1JYplaoNwc5-E: (404) Ad client not found.'
I've been trying to figure out what the Ad client not found means, or if I'm even on the right track for making ads.
Any help would be appreciated.
Sean
Do you need to get the list of available product types from AdClient first to build ads?
Like this part of the returned array from the get function
Array ( [kind] => adsensehost#adClient [id] => ca-host-pub-15831278XXXXXXXX [productCode] => AFC_HOST [supportsReporting] => 1 )
for the insert statement for the adUnit function. accountID is the pubID of the end user correct? So what value should be for adClientID? I think that is where I'm stuck.
Sean
When using the the sample php code, and plug in all the numbers for both IDs I get the following error about adclient not found. Which makes no sense as to why it is doing that.
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/adsensehost/v4.1/accounts/pub-25716040XXXXXXXXX/adclients/74197XXXXXXXXXX.apps.googleusercontent.com/adunits?key=AIzaSyDCXXXXXXXXXvkxQBU1JYplaoNwc5-E: (404) Ad client not found.'
I've been trying to use the try it console from here : https://developers.google.com/adsense/host/v4.1/accounts/adunits/insert
When i fill in the accountID and adClientID and leave the adUnit section blank, I can get the same AdClient not found error as above. And when I fill in the AdCode section to see what response I get, I get this503 Service Unavailable- Show headers -{"error": {"errors": [{"domain": "global","reason": "backendError","message": "Backend Error"}],"code": 503,"message": "Backend Error"}}
I'm wondering if either I'm still missing something, or because I can't get it to work right that there is either a bug in the php sample code that isn't getting the ad unit info through the API correctly, or if something else isn't working quite right.
Sean
I've been using this page to make sure I'm using everything correctly to make the adUnit: https://developers.google.com/adsense/host/v4.1/accounts/adunits/insert
accountID: pub-25716040XXXXXXXX
adClientID: 74197XXXXXXXX.apps.googleusercontent.com
I filled out the fancy html5 box for defining an adUnit to come up with this
{"kind": "adsensehost#adUnit","name": "qq","size": "SIZE_160_600","type": "TEXT"},"code": "hjktrdres421rew","id": "jhftderszzresw5r56"}
And it still comes back with this.503 Service Unavailable
"domain": "global","reason": "backendError","message": "Backend Error"}],"code": 503,"message": "Backend Error"}
}
I think I'm using all the proper everything to make the adUnits right? Then once I create them, I can run the getAdCode function to get the actual Javascript for them correct?
Sean
I'm still having problems getting this to work though using the sample PHP code. I'm plugging in all the numbers and I can't seem to make it work. Is there anything I'm missing here? I still don't know why it is giving me the (404) Ad client not found when I try and insert the ad.
I set up the ad unit as so.
$adUnit = new Google_AdUnit();
$adUnit->setName('Test 1');
$contentAdsSettings = new Google_AdUnitContentAdsSettings();
$backupOption = new Google_AdUnitContentAdsSettingsBackupOption();
$backupOption->setType('COLOR');
$backupOption->setColor('ffffff');
$contentAdsSettings->setBackupOption($backupOption);
$contentAdsSettings->setSize('SIZE_160_600'); //width then height //ledarboard
$contentAdsSettings->setType('TEXT');
$adUnit->setContentAdsSettings($contentAdsSettings);
$customStyle = new Google_AdStyle();
$colors = new Google_AdStyleColors();
$colors->setBackground('ffffff');
$colors->setBorder('000000');
$colors->setText('000000');
$colors->setTitle('000000');
$colors->setUrl('0000ff');
$customStyle->setColors($colors);
$customStyle->setCorners('SQUARE');
$font = new Google_AdStyleFont(); //added Google_ to tihs to make it work
$font->setFamily('ACCOUNT_DEFAULT_FAMILY');
$font->setSize('ACCOUNT_DEFAULT_SIZE');
$customStyle->setFont($font);
$adUnit->setCustomStyle($customStyle);
//print the ad unit to make sure it's all good.
print_r($adUnit);
echo "<BR><BR>";
print out the vars I'm using to make sure it's right
echo "clientid: " . $clientID . "<BR>";
echo "pubID: " . $pubID . "<BR>";
echo "thisAdClientID: " . $thisAdClientID . "<BR>";
//now do the insert
$result = $adsensehostService->accounts_adunits->insert($pubID, $clientID, $adUnit); // $clientID $thisAdClientID $clientID $pubID
echo "<BR><BR>r: " . $result . "<BR>xx<BR>";
Google_AdUnit Object ( [code] => [__contentAdsSettingsType:protected] => Google_AdUnitContentAdsSettings [__contentAdsSettingsDataType:protected] => [contentAdsSettings] => Google_AdUnitContentAdsSettings Object ( [__backupOptionType:protected] => Google_AdUnitContentAdsSettingsBackupOption [__backupOptionDataType:protected] => [backupOption] => Google_AdUnitContentAdsSettingsBackupOption Object ( [color] => ffffff [type] => COLOR [url] => ) [size] => SIZE_160_600 [type] => TEXT ) [__customStyleType:protected] => Google_AdStyle [__customStyleDataType:protected] => [customStyle] => Google_AdStyle Object ( [__colorsType:protected] => Google_AdStyleColors [__colorsDataType:protected] => [colors] => Google_AdStyleColors Object ( [background] => ffffff [border] => 000000 [text] => 000000 [title] => 000000 [url] => 0000ff ) [corners] => SQUARE [__fontType:protected] => Google_AdStyleFont [__fontDataType:protected] => [font] => Google_AdStyleFont Object ( [family] => ACCOUNT_DEFAULT_FAMILY [size] => ACCOUNT_DEFAULT_SIZE ) [kind] => ) [id] => [kind] => [__mobileContentAdsSettingsType:protected] => Google_AdUnitMobileContentAdsSettings [__mobileContentAdsSettingsDataType:protected] => [mobileContentAdsSettings] => [name] => Test 1 [status] => )
clientid: 7419718XXXXX.apps.googleusercontent.com
pubID: pub-25716040709XXXXXX
thisAdClientID: ca-host-pub-158312780XXXXXX
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/adsensehost/v4.1/accounts/pub-2571604070xxxxx/adclients/741971xxxxxxx.apps.googleusercontent.com/adunits?key=AIzaSyDC9eQ8QIO_cTLJvkxQXXXXXXXXwc5-E: (404) Ad client not found.' in D:\Inetpub\wwwroot\site\_googleapi\src\io\Google_REST.php:66 Stack trace: #0 D:\Inetpub\wwwroot\site\_googleapi\src\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 D:\Inetpub\wwwroot\site\_googleapi\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 D:\Inetpub\wwwroot\site\_googleapi\src\contrib\Google_AdsensehostService.php(198): Google_ServiceResource->__call('insert', Array) #3 D:\Inetpub\wwwroot\site\_googleapi\api\build-ads-single.php(153): Google_AccountsAdunitsServiceResource->insert('pub-257160xxxxx...', '7419718xxxxxx.ap...', Object(Google_AdUnit)) #4 {main} thrown in D:\Inetpub\wwwroot\site\_googleapi\src\io\Google_REST.php on line 66
Sean
From this page: https://developers.google.com/adsense/host/v4.1/accounts/adunits/insert
Using accountID = pub-257160407xxxxxx and adClientID = ca-pub-257160407xxxxxx (is that the two IDs I'm supposed to be using?)
Using this AdUnit
{"code": "asfd asdf asf dsadf ","color": "GREEN","type": "COLOR"},
"size": "SIZE_160_600","type": "TEXT"
},"background": "BLUE","border": "GREEN","text": "YELLOW","title": "PURPLE","url": "BLACK"},"corners": "SQUARE","family": "TIMES","size": "MEDIUM"},"kind": "adsensehost#adStyle"},"id": "as fdasdf sa d","kind": "adsensehost#adUnit","name": "adfasfa ","status": "ACTIVE","markupLanguage": "PHP","scriptingLanguage": "PHP",
"size": "SIZE_160_600","type": "TEXT"
}
}
I get a backendError message.
That is where I pulled my above code from and I haven't been able to get it to work. Which is why I was asking you about it.
Which is also why I've been trying to use the Try it now tester form since that doesn't involve coding. But I can't get that to work either.
What am I doing wrong, and how can I get this working?
Sean
Yes, I have changed those vars. I've been trying to say that and get that accross.
Using the above PHP in the first post, for this line of it
insert($pubID, $clientID, $adUnit);
I've been using these values
insert('pub-25716040709XXXXXX', '7419718XXXXX.apps.googleusercontent.com', $adUnit);
That didn't work.
Neither has this. Which I'm not sure if this is right either.
insert('pub-25716040709XXXXXX', 'ca-pub-25716040709XXXXXX', $adUnit);
Sean