• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Python Google API - Script Help

Can you help me with this? When can I run this and where should I replace my information? It's not working on Code Visual Studio

[CODE lang="php" title="API"]import googleads
import pandas as pd
import traceback
from googleads import adwords
from googleads import oauth2

_locale._getdefaultlocale = (lambda *args: ['en_UK', 'UTF-8'])

class searchVolumePuller():
def __init__(self,client_ID,client_secret,refresh_token,developer_token,client_customer_id):
self.client_ID = client_ID
self.client_secret = client_secret
self.refresh_token = refresh_token
self.developer_token = developer_token
self.client_customer_id = client_customer_id

def get_client(self):
access_token = oauth2.GoogleRefreshTokenClient(self.client_ID,
adwords_client = adwords.AdWordsClient(self.developer_token,
client_customer_id = self.client_customer_id,

return adwords_client

def get_service(self,service,client):

return client.GetService(service)

def get_search_volume(self,service_client,keyword_list):
#empty dataframe to append data into and keywords and search volume lists#
keywords = []
search_volume = []
keywords_and_search_volume = pd.DataFrame()
#need to split data into smaller lists of 700#
sublists = [keyword_list[x:x+700] for x in range(0,len(keyword_list),700)]
for sublist in sublists:
# Construct selector and get keyword stats.
selector = {
'ideaType': 'KEYWORD',
'requestType' : 'STATS'

#select attributes we want to retrieve#
selector['requestedAttributeTypes'] = [

#configure selectors paging limit to limit number of results#
offset = 0
selector['paging'] = {
'startIndex' : str(offset),
'numberResults' : str(len(sublist))

#specify selectors keywords to suggest for#
selector['searchParameters'] = [{
'xsi_type' : 'RelatedToQuerySearchParameter',
'queries' : sublist

#pull the data#
page = service_client.get(selector)
#access json elements to return the suggestions#
for i in range(0,len(page['entries'])):

keywords_and_search_volume['Keywords'] = keywords
keywords_and_search_volume['Search Volume'] = search_volume

return keywords_and_search_volume

if __name__ == '__main__':
CLIENT_ID = "my"

keyword_list = ['Manchester','Turin','London']

volume_puller = searchVolumePuller(CLIENT_ID,

adwords_client = volume_puller.get_client()

targeting_service = volume_puller.get_service('TargetingIdeaService', adwords_client)

kw_sv_df = volume_puller.get_search_volume(targeting_service,keyword_list)[/CODE]

New Threads

Latest posts

Buy us a coffee!

Top Bottom