Wednesday, February 11, 2015

Digest for - 5 updates in 2 topics Feb 10 04:01AM -0800

Can I use AdUnit.getAdCode() in PHP?
I can't find it in get_class-methods() of my ad unit.
How do I generate the actual HTML ad code (async + sync) rather than
returning the plain number?
"Dean Lukies (Adsense API Team)" <>: Feb 10 11:43AM -0800

Is this what you are looking for?
$result = $service->accounts_adunits->getAdCode($accountId, $adClientId,
print $result['adCode'];
PS: I wanted to remind people about and the adsense-api
galeksic <>: Feb 10 11:51AM -0800

(Sorry, Dean. I was almost at the end of my message when I saw yours, so
I'll post it anyway :)
I think you can, but of course - just to get and store the code in your
database. (You don't want to call API for every ad request.)
* Get ad code for the specified ad unit. (adunits.getAdCode)
* @param string $adClientId
* Ad client with contains the ad unit.
* @param string $adUnitId
* Ad unit to get the code for.
* @param array $optParams Optional parameters.
* @return Google_Service_AdSense_AdCode
public function getAdCode($adClientId, $adUnitId, $optParams = array())
$params = array('adClientId' => $adClientId, 'adUnitId' => $adUnitId);
$params = array_merge($params, $optParams);
return $this->call('getAdCode', array($params),
$result = $service->accounts_adunits->getAdCode($adClientId, $adUnitId,
"kind": "adsense#adCode",
"adCode": "<script async
* * * -->\n<ins class=\"adsbygoogle\"\n style=\"display:block\"\n
data-ad-client=\"ca-pub-123\"\n data-ad-slot=\"456\"\n
data-ad-format=\"auto\"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle
|| []).push({});\n</script>"
As far I'm aware with getAdCode() you can get only one version - for
responsive asynchronous, and for fixed sized synchronous. (Not 100% sure
about other ad sizes - custom sized, link units.) Feb 10 03:56AM -0800

The endpoint hitting page returns the same error. Just the same 403 User
does not have an AdSense account.
I've invited the new user and accepted the invite and can access the normal
UI from the new user, I just can't do any API calls.
"Dean Lukies (Adsense API Team)" <>: Feb 10 07:31AM -0800

Resolved this offline with Dan but wanted to post so folks know what
happened; it can take up to 24 hours for a new account to get API access.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to

No comments:

Post a Comment