http - How to post to Google Measurement protocol using Python? -
i need example of how post using python.
something this, working.
import httplib, urllib conn = httplib.httpconnection("www.google-analytics.com") conn.request("post", "v=1&tid=ua-xxxxxx-y&cid=666&t=event&ec=game&ea=start&ev=0") response = conn.getresponse() print response.status, response.reason data = response.read() conn.close()
you needed url:
conn.request("post", "/collect", "v=1&tid=ua-xxxxxx-y&cid=666&t=event&ec=game&ea=start&ev=0")
or dictionary:
import httplib, urllib params = urllib.urlencode({ 'v': 1, 'tid': 'ua-xxxxxx-y', 'cid': '666', 't': 'event', 'ec': 'game', 'ea': 'start', 'ev': 0 }) connection = httplib.httpconnection('www.google-analytics.com') connection.request('post', '/collect', params)
Comments
Post a Comment