本文整理汇总了Python中weibopy.api.API.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python API.get_user方法的具体用法?Python API.get_user怎么用?Python API.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weibopy.api.API
的用法示例。
在下文中一共展示了API.get_user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: searchUser
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
def searchUser(self,name):
self.auth.setToken(self.key,self.secret)
api = API(self.auth)
try :
user = api.get_user(screen_name=name)
#print user.id
data = (user.screen_name.encode('utf-8'),user.location.encode('utf-8'),user.followers_count,user.friends_count,user.statuses_count,user.profile_image_url)
return data
except Exception ,e:
pass
示例2: getUser
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
def getUser(self,uid):
self.auth.setToken(self.key,self.secret)
api = API(self.auth)
try :
user = api.get_user(id=uid)
string = self.getTag(uid)
#print string
#print type(string)
#print type(user.screen_name)
data = (user.screen_name.encode('utf-8'),user.id,user.gender,user.province,user.followers_count,string)
#print data
return data
except Exception ,e:
pass
示例3: API
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
except WeibopError, e:
return e.reason;
return friendship;
# 八、获取指定用户信息
from weibopy.error import WeibopError;
#设定用户令牌密钥.
auth.setToken( atKey, atSecret );
#绑定用户验证信息.
api = API(auth);
#获取指定用户信息.
try:
thisUser = {};
result = api.get_user( user_id = user_id,
screen_name = screen_name );
#用户ID
thisUser['id'] = result.id;
#用户名称.
thisUser['name'] = result.name.encode('utf-8');
#所在城市.
thisUser['location'] = result.location.encode('utf-8');
#自我描述.
thisUser['description'] = result.description.encode('utf-8');
#个人主页.
thisUser['url'] = result.url;
#头像图片地址.
thisUser['profile'] = result.profile_image_url;
#是否实名认证.
thisUser['verified'] = result.verified;
示例4: OAuthHandler
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
@author: leishg
'''
from weibopy.api import API
from weibopy.auth import OAuthHandler
App_Key = "1301184712"
App_Secret = "72023ad9cf7e87b163921cc1490c2cef"
auth = OAuthHandler(App_Key, App_Secret)
auth_url = auth.get_authorization_url()
print 'Please authorize: ' + auth_url
verifier = raw_input('PIN: ').strip()
#http://api.t.sina.com.cn/oauth/authorize?oauth_token=4a72f6e4813750610c47f4c86120d0a2
#496558
access_token = "7e4261f41e53aab3e2f7da5c8ffb3f1b"
access_key = "285414"
#auth.get_access_token(verifier)
auth.setToken("0ae7e293bfabc120c74fc25ab234f028", "77083ac464f82da67f5a7764b9d0088d")
api = API(auth)
status = api.get_user(id=1650951660)
print status
#status = api.update_status('³ÇÊлƻè--ºéÆô'.encode("utf-8"))
#print status.id
#print status.text
示例5: login_check
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
status = api.update_status(status='hello world', lat='12.3', long='45.6')
print status.id
print status.text
angies = api.search_users("Angie Zhu")
angie1 = angies[0]
ch = angie1.screen_name
print ch.encode("utf8")
weibos = api.public_timeline()
for weibo in weibos:
print weibo.text.encode('utf8')
user = api.get_user('brothercutter')
print user.screen_name
print user.followers_count #打印粉丝数
for friend in user.friends( ):
print friend.screen_name
def login_check(request):
"""用户成功登录授权后,会回调此方法,获取access_token,完成授权"""
verifier = request.GET.get('oauth_verifier', None)
auth_client = _oauth()
# 设置之前保存在session的request_token
request_token = request.session['oauth_request_token']
del request.session['oauth_request_token']
auth_client.set_request_token(request_token.key, request_token.secret)
access_token = auth_client.get_access_token(verifier)
示例6: classify_influence
# 需要导入模块: from weibopy.api import API [as 别名]
# 或者: from weibopy.api.API import get_user [as 别名]
def classify_influence(inf_id, other=False):
"""
TODO:
1, Calculate the most popular tags, so that we can assign idf score
2, Accumulate more meaningful tags
"""
inf_id = inf_id.decode('gbk')
print inf_id.encode('gbk')
try:
inf_id = int(inf_id)
inf = Influence.objects.get(pk=inf_id)
except:
inf, created = Influence.objects.get_or_create(screen_name=inf_id)
if created:
auth = OAuthHandler(settings.SINA_CONSUMER_KEY, settings.SINA_CONSUMER_SECRET)
auth.setToken('128021658f2bfdae185d89bdffb3cede','1713185d5c8208e8f1ef27a1f484ebc9')
api = API(auth)
user = api.get_user(screen_name=inf_id)
inf.sina_account = getAtt(user, 'id')
inf.verified = getAtt(user,'verified')
inf.screen_name = getAtt(user, 'screen_name')
inf.description = getAtt(user, 'description')
inf.follower_count = getAtt(user, 'followers_count')
inf.following_count = getAtt(user, 'friends_count')
inf.status_count = getAtt(user, 'statuses_count')
inf.favourites_count = getAtt(user, 'favourites_count')
inf.create_date = getAtt(user, 'created_at')
inf.save()
auth = OAuthHandler(settings.SINA_CONSUMER_KEY, settings.SINA_CONSUMER_SECRET)
if other:
auth.setToken('128021658f2bfdae185d89bdffb3cede', '1713185d5c8208e8f1ef27a1f484ebc9')
else:
auth.setToken(inf.sina_key, inf.sina_secret)
api = API(auth)
mmseg.dict_load_defaults()
"""Put this in db first"""
candidate_tags = KeyValue.objects.get(key='CANDIDATE_TAGS')
area_dict = {}
# id_list = api.followers_ids(user_id=inf.sina_account, count=100) #default to 500, maximum is 5000; This consumes a lot of api limit
# ids = id_list[0].ids #Weird that getAtt won't work
# for id in ids:
# tags = api.tags(user_id=id) #user_id is required!
# tag_list = []
# for tag in tags:
# tag_list.append(getAtt(tag, 'value').lower().encode('utf-8'))
# mmseg_text = mmseg.Algorithm(' '.join(tag_list))
# for token in mmseg_text:
# try:
# term = token.text.decode('utf-8').lower()
# #next_term = mmseg_text[i+1].text.decode('utf-8') if i < len_list - 1 else ''
# except:
# continue
# train_value = area_train_data.get(term, None)
# #if not train_value:
# # train_value = area_train_data.get(term + next_term, None)
# if train_value:
# print 'in dict'
# for index in train_value:
# if index in area_dict:
# area_dict[index] += 1
# else:
# area_dict[index] = 1
# else:
# candidate_tags.value += ' ' + term
candidate_tags.save()
area_distr_dict = {}
mid_list = []
ids_list = []
tweet_list = [] #Store the text of tweet and retweet
rt_count_list = []
tried_count = 0
while True:
timeline = api.user_timeline(user_id=inf.sina_account, count=200)
if len(timeline) == 0 and inf.status_count >0:
tried_count += 1
print 'try again in getting timeline'
else:
break
if tried_count > 3:
raise Exception('weibo api error. No timeline got')
break
for line in timeline:
text = getAtt(line, 'text')
retweet = getAtt(line, 'retweeted_status')
retweet_text = getAtt(retweet, 'text')
if retweet_text:
text += retweet_text
tweet_list.append(text)
mid_list.append(str(getAtt(line, "id")))
if len(mid_list) == 20:
ids_list.append(','.join(mid_list))
mid_list = []
if mid_list: #append the remaining ids
ids_list.append(','.join(mid_list))
if inf.status_count > 0 and not ids_list:
#.........这里部分代码省略.........