from google.auth import load_credentials_from_file
from google.auth.transport.requests import Request
from google.ads.google_ads.client import GoogleAdsClient


def authenticate():
credentials = {
"developer_token": "",
"refresh_token": "",
"client_id": "6001597233",
"client_secret": "",
}
credentials = load_credentials_from_file(credentials)
if credentials.expired:
credentials.refresh(Request())
return credentials


def fetch_campaign_data(client):
query = """
SELECT
segments.month,
segments.year,
segments.date,
campaign.account_budget,
campaign.name,
campaign.id,
metrics.impressions,
metrics.clicks,
metrics.cost_micros,
metrics.ctr,
metrics.average_cpc,
metrics.average_cpm,
metrics.interactions,
metrics.engagements,
metrics.average_cost
FROM
campaign
WHERE
segments.date DURING LAST_1_DAYS
"""
page_size = 1000
current_page = 1
response = client.service.google_ads.search(
query=query, page_size=page_size, page=current_page
)
print(response)

while response.next_page_token:
current_page += 1
response = client.service.google_ads.search(
query=query, page_size=page_size, page=current_page
)
print(response)


def main():
credentials = authenticate()
client = GoogleAdsClient.load_from_credentials(credentials)
print(client)
fetch_campaign_data(client)


if __name__ == "__main__":
main()





AFTER INSTALLING pip3 install google-ads
still getting error-



 File "/Users/basantkumar/google_ads/test.py", line 3, in <module>
    from google.ads.google_ads.client import GoogleAdsClient
ModuleNotFoundError: No module named 'google.ads.google_ads'

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/9527b4d9-302f-45e5-a38b-6f3e0ac0770en%40googlegroups.com.
  • Er... Basant Kumar
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to