GA requires a string for start_date and end_date. I have a text file that has a list dates that I want to iterate through. When I try the following code:
def get_results(service, profile_id):
for x in open("C:\\E\\dates.txt"):
print type(x)
print x
# Use the Analytics Service Object to query the Core Reporting
return service.data().ga().get(
ids='ga:' + profile_id,
start_date=x, # YYYY/MM/DD
end_date=x,
dimensions='ga:date,ga:deviceCategory',
metrics='ga:sessions,ga:users,ga:pageviews').execute()
I get the error: Arg, there was an API error : 400 : Invalid value '2015-02-11 '. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'
I checked the type(x) and it returns type 'str' in powershell. If I am returning a string, why is it not being accepted as a valid start/end date?
When I run the code:
def get_results(service, profile_id):
x = '2015-02-01'
print x
# Use the Analytics Service Object to query the Core Reporting API
return service.data().ga().get(
ids='ga:' + profile_id,
start_date=x, # YYYY/MM/DD
end_date=x,
dimensions='ga:date,ga:deviceCategory',
metrics='ga:sessions,ga:users,ga:pageviews').execute()
I do not receive an error and the type(x) returns type 'str'
Thank you for any help.