Error

100 views
Skip to first unread message

Basant Kumar

unread,
Jul 4, 2023, 4:32:41 AM7/4/23
to Google Ads API and AdWords API Forum
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'

Google Ads API Forum Advisor

unread,
Jul 4, 2023, 8:14:36 AM7/4/23
to basa...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for reaching out to Google Ads API Support.

With regards to your concerns, can you provide more context about your issue? This is so that we can investigate this matter and provide you proper guidance. Please note that in Google Ads API perspective we need the complete logs to be able to see the error thrown on your side and further investigate. With that being said, can you provide the complete request and response logs with request ID generated as shown in the respective?

Moreover, logging can be enabled by navigating to the Client libraries > Your client library (ex. Java) > Logging documentation, which you can access from the link below. For REST interface requests, you can enable logging via the curl command by using the -i flag. This will cause the tool to include the HTTP response headers in the output.

Additionally, can you confirm if you are using the python library for configuration? If so, then your may refer to this link (https://developers.google.com/google-ads/api/docs/client-libs/python/installation) for python installation and this link (https://developers.google.com/google-ads/api/docs/client-libs/python/configuration) for python configuration.

You may then send the requested information via the Reply privately to the author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Links included in this email:

 
This message is in relation to case "ref:_00D1U1174p._5004Q2mrEwB:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages