I'm trying to do a Google Analytics batch request in Python.
batch.add(service.data().ga().get(
ids=ids,
start_date=start_date,
end_date=end_date,
metrics=metrics,
dimensions=dimensions,
segment=segment,
sort=sort), callback=process_response)
From the documentation (https://developers.google.com/api-client-library/python/guide/batch):
The add() method also allows you to supply a request_id parameter for each request. These IDs are provided to the callbacks. If you don't supply one, the library creates one for you. The IDs must be unique for each API request, otherwise add() raises an exception.
So if I create a function process_response like this:
def process_response(request_id, response, exception):
print response
I get the callback result in these variables. These variables are automatically generated by the Google Analytics library and it works fine. However, I want to add another argument, page_id, to the process_response function, in order to link a page_id with the results from the callback. However if I do this:
def process_response(page_id, request_id, response, exception):
print response
and then:
callback=process_response(page_id)
I get an error:
TypeError: process_response() takes exactly 4 arguments (1 given)
So it comes down to this: I want to call a function that takes 4 arguments while only supplying 1 argument (page_id) so the other 3 arguments can be automatically generated by the Google Analytics library. Is this possible? Or is there another way to link the page_id to the response?
Any help would be greatly appreciated, I'm completely stuck! Thanks in advance!