Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.
Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/
class Util{
public static function getIdUnformat($id) { $id_adwords=str_replace('-', '', $id); return $id_adwords; }
public static function getGoogleAdsClient() { $cliente_id = env('ADWORDS_CLIENT_ID'); $cliente_secret = env('ADWORDS_CLIENT_SECRET'); $token = env('ADWORDS_TOKEN'); $developer_token = env('ADWORDS_DEVELOPER_TOKEN'); $id_account_mcc = self::getIdUnformat(env('ADWORDS_ID_MCC'));
$oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId($cliente_id) ->withClientSecret($cliente_secret) ->withRefreshToken($token) ->build();
$googleAdsClient = (new GoogleAdsClientBuilder()) ->withDeveloperToken($developer_token) ->withLoginCustomerId($id_account_mcc) ->withOAuth2Credential($oAuth2Credential) ->build(); return $googleAdsClient; }}
class TestController extends Controller{ const PAGE_SIZE = 100;
public function convertionAction() { $cid = "xxx-xxx-xxxx";
$cid = Util::getIdUnformat($cid); $googleAdsClient = Util::getGoogleAdsClient(); $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = "SELECT ad_group.id, ad_group.status FROM ad_group WHERE ad_group.status = 'ENABLED' ";
$response = $googleAdsServiceClient->search($cid, $query, ['pageSize' => self::PAGE_SIZE]);
foreach ($response->iterateAllElements() as $googleAdsRow) { printf( "ad_group.name %s, ad_group.status %s%s", $googleAdsRow->getAdGroup()->getId()->getValue(), $googleAdsRow->getAdGroup()->getStatus(), PHP_EOL ); }
}}class Util{
public static function getIdUnformat($id) { $id_adwords=str_replace('-', '', $id); return $id_adwords; }
public static function getGoogleAdsClient() { $cliente_id = env('ADWORDS_CLIENT_ID'); $cliente_secret = env('ADWORDS_CLIENT_SECRET'); $token = env('ADWORDS_TOKEN'); $developer_token = env('ADWORDS_DEVELOPER_TOKEN'); $id_account_mcc = self::getIdUnformat(env('ADWORDS_ID_MCC'));
$oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId($cliente_id) ->withClientSecret($cliente_secret) ->withRefreshToken($token) ->build();
$googleAdsClient = (new GoogleAdsClientBuilder()) ->withDeveloperToken($developer_token) ->withLoginCustomerId($id_account_mcc) ->withOAuth2Credential($oAuth2Credential) ->build(); return $googleAdsClient; }}
class TestController extends Controller{ const PAGE_SIZE = 100;
public function convertionAction() { $cid = "xxx-xxx-xxxx";
$cid = Util::getIdUnformat($cid); $googleAdsClient = Util::getGoogleAdsClient(); $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = "SELECT ad_group.id, ad_group.status FROM ad_group WHERE ad_group.status = 'ENABLED' ";
$response = $googleAdsServiceClient->search($cid, $query);
foreach ($response->iterateAllElements() as $googleAdsRow) { printf( "ad_group.name %s, ad_group.status %s%s", $googleAdsRow->getAdGroup()->getId()->getValue(), $googleAdsRow->getAdGroup()->getStatus(), PHP_EOL ); }
}}