Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

python - Query ADH using a filter

I am trying to query the Google ADH API (https://developers.google.com/ads-data-hub/reference/rest/v1/customers.adsDataLinks/list)

For reference I get a response sample as:

  {'name': 'customers/68689789/adsDataLinks/XXXXXXXXXX',
  'linkedEntity': {'entityId': '897777777', 'type': 'GOOGLE_ADS_CAMPAIGN'},
  'parentEntity': {},
  'platform': 'GOOGLE_ADS',
  'customerLink': {'name': 'xyz/780/78',
  'customerId': '97896868',
   'displayName': 'VENDOR_ID'},
  'status': 'APPROVED',
  'createTime': '2020-04-04T16:51:47.738710Z',
  'updateTime': '2020-04-04T16:51:47.738710Z'
}

I have everything set up so that I can query ADH using a client. I have written a function

        datesss='2020-04-04T16:51:47.738710Z'
        kwargs = {
            'parent': self.parent,
            'filter':f"updateTime={datesss}",
            'pageSize': 1,
            'pageToken': pageToken
        }
        request = self.service.customers().adsDataLinks().list(**kwargs)
        response = self.execute_adh_request(request)

        return response.get('links', []), response.get('nextPageToken', '')

I get this error: HttpError: <HttpError 400 when requesting https://adsdatahub.googleapis.com/v1/customers/802/adsDataLinks?filter=updateTime%3D2020-04-04T16%3A51%3A47.738710Z&pageSize=1&pageToken=&key=AIzaSyBsDsBR-PhJu2kUiH9O_tRgLfdLP9L_YUo&alt=json returned "Invalid filter expression: updateTime=2020-04-04T16:51:47.738710Z (Error 0420)">

I then enclosed the filter expression as such as

'filter':f"updateTime='{datesss}'"

NOTE: This is just a sample, I want to extract all links that have a creation date in 2021 Please can someone guide me how I can use the filter function to do this.

question from:https://stackoverflow.com/questions/65910852/query-adh-using-a-filter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think filter is currently only supported on text fields, I have tested title and email. Date filters are not working with same error above. Also to note, text search is finicky, works only when using wildcards example:

'filter':"title=vendor*"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...