def get_username(self): if self.username is None: api = API(self) user = api.user.info() if user: self.username = user.name else: raise QWeiboError( "Unable to get username, invalid oauth token!") return self.username
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) token = 'your token' tokenSecret = 'yourr tokenSecret' auth.setToken(token, tokenSecret) # this time we use ModelParser() api = API(auth) # ModelParser is the default option """ Avaliable API: api.user.info api.user.otherinfo api.user.update api.user.updatehead api.user.userinfo NOTE: api.me api.info api.user.info 功能相同 """
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']