使用python sdk读取weibo粉丝列表,pythonweibo,调用python sdk
使用python sdk读取weibo粉丝列表,pythonweibo,调用python sdk
调用python sdk读取weibo粉丝列表
#!/usr/bin/env python-*-coding: utf-8 -*-from weibo import APIClientimport urllibimport urllib2import httplibimport redef get_code(): ‘’‘ 自动获取code ’‘’ conn = httplib.HTTPSConnection(‘api.weibo.com’) params = urllib.urlencode({ ‘action’:‘submit’, ‘withOfficalFlag’:‘0’, ‘ticket’:‘’, ‘isLoginSina’:0, 'response_type‘:’code', ‘regCallback’:‘’, 'redirect_uri':REDIRECT_URL, 'client_id':APP_KEY, ‘state’:‘’, ‘from’:‘’, ‘userId’:USERID, ‘passwd’:USERPASSWD, }) conn.request(‘POST’,‘/oauth2/authorize’, params, {‘Referer’: url, ‘Content-Type’: ‘application/x-www-form-urlencoded’}) res = conn.getresponse() for line in res.msg.headers: if re.search(‘Location’, line): return line.strip().split(‘=’)[1] conn.close()def get_fans(code): fans_list = [] client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=REDIRECT_URL) r = client.request_access_token(code) access_token = r.access_token expires_in = r.expires_in client.set_access_token(access_token, expires_in) next_cursor = 0 total_fans = client.friendships.followers.get(uid=UID, cursor=next_cursor, count=10)['total_number'] us = client.friendships.followers.get(uid=UID, cursor=next_cursor, count=total_fans)[‘users’] for u in us: fans_list.append(u) return total_fans, fans_listif name == 'main': APP_KEY = ‘951598xxx’ APP_SECRET = ‘5b5ff4exxxxxxxxxxxxx’ REDIRECT_URL = 'https://api.weibo.com/oauth2/default.html' USERID = ‘username’ USERPASSWD = ‘password’ UID = ‘xxxxxxxxx’ url = 'https://api.weibo.com/oauth2/authorize?redirect_uri=%s&response_type=code&client_id=%s&display=default' % (urllib.quote(REDIRECT_URL), APP_KEY) c = get_code() total_fans, fans_list = get_fans(c) print ‘粉丝数: %s’ % total_fans for fans in fans_list: print '%s\t%s' % (fans[‘id’], fans['screen_name'])
相关内容
- Python的xor 异或逻辑实现,pythonxor逻辑,python中没有异或
- Python的位运算,Python运算,Python语言能够对整
- 如何检查端口是否是被占用,检查端口占用,如下一小段
- 阿里云开放搜索的python客户端,阿里云python客户端,阿里
- 阿里云收集服务器性能指标的python脚本,阿里python,下面
- ubuntu安装python3的python-pip,python3python-pip,python-pip默认
- python读取yaml,pythonyaml,python读取yaml
- python获得linux服务器的内存使用率,虚拟内存使用率,
- 64位系统编译Python,64位编译python,如果在64位系统下默认
- python计算文件的md5值,python计算md5,from hashlib
评论关闭