Question

I'm trying to pass in some parameters to the link_clicks and link_countries bit.ly APIs with python however I'm not sure of the syntax to pass the parameters here. How can I add parameters to this api call?

import sys
import bitly_api
import os
from config import config


#connect to bitly
conn_btly = bitly_api.Connection(access_token=config['ACCESS_TOKEN'])

#get links
links = conn_btly.user_link_history()

print 'links okay'


for link in links:

    #add params to link
    link_full = link['link'] + '?rollup=false'
    print link_full

    #get clicks
    clicks = conn_btly.link_clicks(link_full)

    #print results
    #print link['link'], clicks
    print clicks

the resulting output is

links okay
http://mzl.la/19xSyCT?rollup=false
...
BitlyError: NOT_FOUND
Was it helpful?

Solution

You need to pass in rollup as a keyword parameter instead:

clicks = conn_btly.link_clicks(link['link'], rollup=False)

You are expected to pass in a Python boolean value. The parameter is not part of the bit.ly URL, it is a parameter to the API call instead.

All optional API parameters (so apart from the link), are passed in as keyword parameters, including unit, units, tz_offset and limit.

You can take a look at the internal method that handles these parameters if you are so inclined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top