Google Ads API Query Not Returning Any Rows for Keyword Plan

I’m working with the Google Ads API and trying to fetch keyword ideas from an existing keyword plan using Python. However, my query isn’t returning any rows, and I’m not sure why. Here’s the relevant part of my code (API V15):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def extract_google_ads_keywords(self, keyword_plan_name='sqlxpert.de'):
try:
ga_service = self.client.get_service("GoogleAdsService")
#ga_service = self.client.get_service("KeywordPlanIdeaService")
# Define the query to fetch the keyword ideas
keyword_plan_query = f"""
SELECT
keyword_plan.id,
keyword_plan.name,
keyword_plan.resource_name
FROM
keyword_plan
WHERE
keyword_plan.name = '{keyword_plan_name}'
"""
print("Customer ID:", self.customer_id)
print("Query:", keyword_plan_query)
# Execute the query to get the keyword plan campaigns
keyword_plan_stream = ga_service.search_stream(customer_id=self.customer_id, query=keyword_plan_query)
# Initialize an empty list to hold all rows' data
results = []
# Iterate through the returned results
for batch in keyword_plan_stream:
for row in batch.results:
print(row) # Debug: print each row to see what is returned
data = {
'KeywordPlanID': row.keyword_plan.id,
'Name': row.keyword_plan.name,
'ResourceName': row.keyword_plan.resource_name
}
results.append(data)
if not results:
print("No data returned from the query.")
# Convert the list of dictionaries to a DataFrame
df = pd.DataFrame(results)
print(df.head())
</code>
<code>def extract_google_ads_keywords(self, keyword_plan_name='sqlxpert.de'): try: ga_service = self.client.get_service("GoogleAdsService") #ga_service = self.client.get_service("KeywordPlanIdeaService") # Define the query to fetch the keyword ideas keyword_plan_query = f""" SELECT keyword_plan.id, keyword_plan.name, keyword_plan.resource_name FROM keyword_plan WHERE keyword_plan.name = '{keyword_plan_name}' """ print("Customer ID:", self.customer_id) print("Query:", keyword_plan_query) # Execute the query to get the keyword plan campaigns keyword_plan_stream = ga_service.search_stream(customer_id=self.customer_id, query=keyword_plan_query) # Initialize an empty list to hold all rows' data results = [] # Iterate through the returned results for batch in keyword_plan_stream: for row in batch.results: print(row) # Debug: print each row to see what is returned data = { 'KeywordPlanID': row.keyword_plan.id, 'Name': row.keyword_plan.name, 'ResourceName': row.keyword_plan.resource_name } results.append(data) if not results: print("No data returned from the query.") # Convert the list of dictionaries to a DataFrame df = pd.DataFrame(results) print(df.head()) </code>
def extract_google_ads_keywords(self, keyword_plan_name='sqlxpert.de'):
    try:
        
        ga_service = self.client.get_service("GoogleAdsService")
        #ga_service = self.client.get_service("KeywordPlanIdeaService")

        # Define the query to fetch the keyword ideas
        keyword_plan_query = f"""
            SELECT
                keyword_plan.id,
                keyword_plan.name,
                keyword_plan.resource_name
            FROM
                keyword_plan
            WHERE
                keyword_plan.name = '{keyword_plan_name}'
        """
        
        print("Customer ID:", self.customer_id)
        print("Query:", keyword_plan_query)
        
        # Execute the query to get the keyword plan campaigns
        keyword_plan_stream = ga_service.search_stream(customer_id=self.customer_id, query=keyword_plan_query)
        
        # Initialize an empty list to hold all rows' data
        results = []
        
        # Iterate through the returned results
        for batch in keyword_plan_stream:
            for row in batch.results:
                print(row)  # Debug: print each row to see what is returned
                data = {
                    'KeywordPlanID': row.keyword_plan.id,
                    'Name': row.keyword_plan.name,
                    'ResourceName': row.keyword_plan.resource_name
                }
                results.append(data)
        
        if not results:
            print("No data returned from the query.")
        
        # Convert the list of dictionaries to a DataFrame
        df = pd.DataFrame(results)
        print(df.head())

I have got a “correct” query, correct customer_id and no error from google. Just no rows. Other queries e.g. regarding campaign do work also If i e.g. add keyword_plan.campaign i get an error debug_error_string = “UNKNOWN:Error received from peer ipv4:142.111.111.202:443 {created_time:”2024-07-04T16:46:00.5007365+00:00”, grpc_status:3, grpc_message:”Request contains an invalid argument. So the syntax seems to be ok.

This is the info i want to get back.
My main goal is actually to get the number of searches for the keywords within the plan.
But to make it easier i just made a simple query, although the ones regarding keyword.text etc. are not working either.

grpc not really my link
this i thought would be useful

What am i doing wrong? Wrong Service? Wrong Query? if you could help me i would be really happy!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật