Example #1
0
API_KEY = 'your key'
API_SECRET = 'your secret'

if API_KEY.startswith('your'):
    print u'必须正确填写 API_KEY 和 API_SECRET'
    raise SystemExit('You must set API_KEY and API_SECRET')

auth = OAuthHandler(API_KEY, API_SECRET)

## use get_authorization_url if you haven't got a token
url = auth.get_authorization_url()
print 'Open', url, 'in your browser'
webbrowser.open_new(url)
verifier = raw_input('Your PIN: ').strip()
auth.get_access_token(verifier)

## or if you already have token
#token = 'your token'
#tokenSecret = 'yourr tokenSecret'
#auth.setToken(token, tokenSecret)


# now you have a workable api
api = API(auth, parser=JSONParser())
# or use `api = API(auth)`

I = api.me()
print I
data = I['data']
print data['name'], data['nick'], data['location']