Sunday, 15 August 2010

python - base64 encode a JSON for Mixpanel API pixel tracker -



python - base64 encode a JSON for Mixpanel API pixel tracker -

according mixpanel doc, need base64 json array before sending api endpoint

json = {"event": "e-mail opened", "properties": { "distinct_id": "28224", "token": "494f5d201963457e632d463d1d4745e4", "time": int(time.time()), "campaign": "gameweek 27" } }

per doc, need send that

http://api.mixpanel.com/track/?data=[base_64_json_event]&ip=1&img=1

here's python code convert dict base64 , send it. get

data = base64.b64encode(json.dumps(json)) url = 'http://api.mixpanel.com/track/?data=%d&ip=1&img=1'%data requests.get(url)

my problem doesn't track anything. if convert same dict using this online converter , build url manually work.

so there's who's not working in encoding what?

thanks!

not sure if typo in question, instead of:

url = 'http://api.mixpanel.com/track/?data=%d&ip=1&img=1'%data

it should

url = 'http://api.mixpanel.com/track/?data=%s&ip=1&img=1'%data

as %d expects number, not string, %s does

python mixpanel

No comments:

Post a Comment