Easier way to Query All Data / iterate all date out of the stream [PHP]

769 views
Skip to first unread message

Floyd van der weij

unread,
Jan 15, 2021, 8:27:07 AM1/15/21
to AdWords API and Google Ads API Forum
I have been looking into getting the data from google ads to a csv.

I had a few issues while doing this.

1.
After Searching alot, i found the SQL builder.
but i need EVERY single thing. but currently i have the hugest string in the world.
*not that it matters* but still.

2. 
I tried to get all the data out of the stream :
$Stream = $Connection->searchStream($CustomerID, $Query);

But i have to give things like :
$ad_group = $Stream   ->GetAdGroup();
$ad_group_ad = $Stream   ->GetAdGroupAd();
$ad_group_ad_asset_view = $Stream   ->GetAdGroupAdAssetView();

i have seen the forum, and reffrences of what you can call.
but some things arent working
and isnt there a faster way of calling the data?
and a smaller way?

with kind regards 
- Floyd

Google Ads API Forum Advisor Prod

unread,
Jan 15, 2021, 3:59:52 PM1/15/21
to floy...@gmail.com, adwor...@googlegroups.com

Hi Floyd,

Thank you for reaching out. Unfortunately, the Google Ads API could not provide reports with CSV format. To check what you can fetch from the returned response you could look into the response object to see what entities are available. You could also use the intellisense of your IDE to check the available options. One other trick is to look into the corresponding resource to discover what fields and metrics are exposed from the API. The workaround to convert returned results to CSV files is to convert the response object to CSV format using the Java libraries such as FileUtils.

Thanks and regards,
Xiaoming, Google Ads API Team

 

Google Logo
Xiaoming
Google Ads API Team
 


ref:_00D1U1174p._5004Q2B0bRm:ref

Floyd van der weij

unread,
Jan 18, 2021, 2:24:21 AM1/18/21
to AdWords API and Google Ads API Forum
I diddnt mean to let the google api handle the csv.
But i meant that in PHP, is there a efficiënt way of Getting ALL the data from campaign's, Ads, Ad Campaigns Etc.
Without trying to write a list of 100 Query's?

On the 2nd thing,
The Smart IDE idea is great and it saved me alot of time already.
Thank you.


Op vrijdag 15 januari 2021 om 21:59:52 UTC+1 schreef adsapiforumadvisor:

Google Ads API Forum Advisor Prod

unread,
Jan 18, 2021, 11:21:54 AM1/18/21
to floy...@gmail.com, adwor...@googlegroups.com

Hi Floyd,

Thank you for reaching out. If you would like to get all the fields of an entity in the response, you could consider using the get method such as CampaignService.GetCampaign(), this would return all the fields of a campaign. The difference between the get and the search or searchStream methods is that  the get method returns all fields fully populated but the search and searchStream methods return just the fields you're interested in.



Thanks and regards,
Xiaoming, Google Ads API Team
 

Floyd van der weij

unread,
Jan 19, 2021, 3:11:07 AM1/19/21
to AdWords API and Google Ads API Forum
That helped me out alot, once again thank you.

But i still have an issue with finding out how to call data out of Objects like : [GetCampaign] or even [AdGroups] and more.

For Example i have :
$Campaign = $Element->GetCampaign();
But since Campaign Is still an "Object", i Need to call things like
$CampaignName = $Campaign->GetCampaignName();

Only here is my Question :
Where can i find things like GetCampaignName and more.

in the past i found a list in the Refrence section of google Dev.
But 80% diddnt work, so i was probably at the wrong place.
Op maandag 18 januari 2021 om 17:21:54 UTC+1 schreef adsapiforumadvisor:

Google Ads API Forum Advisor Prod

unread,
Jan 19, 2021, 12:09:22 PM1/19/21
to floy...@gmail.com, adwor...@googlegroups.com

Hi Floyd,

Thank you for reaching out. You could directly go to the specific resource you are interested in such as the campaign resource to look up the available methods that return the fields. One other way is what I had mentioned earlier that you could use the intellisense of the IDE to check the possible options for the resource.



Thanks and regards,
Xiaoming, Google Ads API Team

Floyd van der weij

unread,
Jan 20, 2021, 3:14:49 AM1/20/21
to AdWords API and Google Ads API Forum
This is my last Message For this topic. (and will create a new one for a new question)
But i wanted to clarify for people who have/had the same issue as me and are searching for a answer.

For PHP :
When Calling Elements from a Stream Aka : $Stream = $Connection->searchStream($CustomerID, $Query);

When you Foreach The Data you usually have something like this :
foreach ($Stream->iterateAllElements() as $Element) {

  // ALL Data out of the Object Campaign.
  $campaign = $Element->GetCampaign('GetCampaignRequest');
  // Name.
  $name = $Element->GetName();
  // Status.
  $status = $Element->?????();

}

Status is unknown but, you can find that at :
(Depending on libary, But in V6 its usually) :
google-ads-php/src/Google/Ads/GoogleAds/V6/Recources/Campaign.php
Or if you have something like AdGroups
google-ads-php/src/Google/Ads/GoogleAds/V6/Recources/AdGroup.php


But i wanted to say thank you for your help.


Floyd van der weij

unread,
Jan 20, 2021, 3:16:04 AM1/20/21
to AdWords API and Google Ads API Forum
EDIT:   $campaign = $Element->GetCampaign('GetCampaignRequest');  is suppose to be   $campaign = $Element->GetCampaign('"');  


Op woensdag 20 januari 2021 om 09:14:49 UTC+1 schreef Floyd van der weij:

Google Ads API Forum Advisor Prod

unread,
Jan 20, 2021, 2:47:03 PM1/20/21
to floy...@gmail.com, adwor...@googlegroups.com

Hi Floyd,

Thank you for reaching out. You would be able to use the getStatus() from the campaign resource. Please follow the naming conventions from this code snippet to avoid errors.



Thanks and regards,
Xiaoming, Google Ads API Team
 

Google Logo
Xiaoming
Google Ads API Team
 


ref:_00D1U1174p._5004Q2B1m4Q:ref
Reply all
Reply to author
Forward
0 new messages