本篇文章给大家谈谈新浪微博的api接口,以及新浪微博的api接口有哪些对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
今天给各位分享新浪微博的api接口的知识,其中也会对新浪微博的api接口有哪些进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
如何通过python调用新浪微博的API来爬取数据
先上结论,通过公开的api如果想爬到某大v的所有数据,需要满足以下两个条件:
1、在你的爬虫开始运行时,该大v的所有微博发布量没有超过回溯查询的上限,新浪是2000,twitter是3200。
2、爬虫程序必须不间断运行。
新浪微博的api基本完全照搬twitter,其中接口的参数特性与底层的NoSQL密不可分,建议先看点Nosql数据库的设计理念有助于更好的理解api设计。
一般来说,如果决定爬某个大v,第一步先试获取该用户的基本信息,中间会包含一条最新的status,记下其中的id号作为基准,命名为baseId。
接口中最重要的两个参数:
since_id:返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
max_id:返回ID小于或等于max_id的微博,默认为0。
出于各种原因,获取statuses的接口,固定为按id降序排列(scan_index_forward=false),即最新的statuses返回在前。假设该微博第一天上线,就一个用户,发了一百条,id是1到100。而你在该用户发了第50条的时候开始运行的爬虫,即baseId=50。

新浪微博api接口,能够将长链接转为短链接,怎么进行测试该接口
1:无论多长的微博,都能够转成固定长短的短链,防止某些连接太长影响用户输入其他内容。 2:所有短链在算法上无法直接解链,必须经过新浪的服务器,把链接系统控制到自己的手上。这对网络内容审察来说作用极其大,如果有人发的微博包含敏感内容
如何通过python调用新浪微博的API
1.下载SDK
使用python调用API的话,首先要去下一个Python的SDK,sinaweibopy
连接地址在此: http://michaelliao.github.com/sinaweibopy/
可以使用pip很快的导入,github连接里的wiki也有入门的使用方法,很容易看懂。
2.理解新浪微博的授权机制
在调用API之前,首先要搞懂什么叫OAuth 2,即新浪微博的授权机制,
连接在此: http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E
3.在新浪微博注册应用
每个人都可以通过新浪微博开发者平台注册自己的应用,我注册的是站内应用。注册后会为每个应用分配唯一的app key 和 app secret,这在上文提到的授权机制中需要用到,相当与每个应用的标示吧。
至此,我们可以尝试写代码调用新浪微博的API啦。
4.简单的调用API实例
参考了往上很多资料和文档,写了一个简单的调用过程。
# _*_ coding: utf-8 _*_
from weibo import APIClient
import webbrowser
APP_KEY = ''
APP_SECRET = ''
CALLBACK_URL = ''
#这个是设置回调地址,必须与那个”高级信息“里的一致
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
url = client.get_authorize_url()
# TODO: redirect to url
#print url
webbrowser.open_new(url)
# 获取URL参数code:
code = '2fc0b2f5d2985db832fa01fee6bd9316'
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
r = client.request_access_token(code)
access_token = r.access_token # 新浪返回的token,类似abc123xyz456
expires_in = r.expires_in # token过期的UNIX时间:http://zh.wikipedia.org/wiki/UNIX%E6%97%B6%E9%97%B4
# TODO: 在此可保存access token
client.set_access_token(access_token, expires_in)
print client.friendships.friends.bilateral.ids.get(uid = 12345678)
通过以上的代码,我实现了调用相互关注API的调用,即查找与某个id的用户相互关注的人的列表。
其中,APP_KEY和APP_SECRET就是前文中分配给每个应用的信息,回调地址在每个应用的高级信息中可以看到,需要自己设置,不过随便设置一下就好
比较恶心的是code的获取,我一开始看sinaweibopy的文档的时候也没弄懂是什么意思,如上面的代码所示,url得到的是一个授权的网址,我们通过
webbrowser.open_new(url)
这行代码打开浏览器跳转到授权的界面,然后观察所在界面的网址,会显示大概如下一样的格式:
http://apps.weibo.com/sayarywei?code=505e3efcdad1f421d147db7276aabdbe
看到了吗新浪微博的api接口? 问号后面有一个code=……的一个东西,把等号后面的字符串拷贝下来赋给code就可以了,但是每次运行程序是code不是一成不变的,也就是说每次都要有这么一个手动获取的过程,我觉得很麻烦,以后自己再研究一下,实现自动获取code就好了。如果能有哪位大神告诉我,感激不尽~
好了,得到正确的code之后就可以完成授权认证,也就可以调用微博的API啦,至于如何在Python下调用,我拷贝一下sinaweibopy上的介绍:
首先查看新浪微博API文档,例如:
API:statuses/user_timeline
请求格式:GET
请求参数:
source:string,采用OAuth授权方式不需要此参数,其新浪微博的api接口他授权方式为必填参数,数值为应用的AppKey?。
access_token:string,采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。
uid:int64,需要查询的用户ID。
screen_name:string,需要查询的用户昵称。
(其它可选参数略)
调用方法:将API的“/”变为“.”,根据请求格式是GET或POST,调用get ()或post()并传入关键字参数,但不包括source和access_token参数:
r = client.statuses.user_timeline.get(uid=123456)
for st in r.statuses:
print st.text
若为POST调用,则示例代码如下:
r = client.statuses.update.post(status=u'测试OAuth 2.0发微博')
若需要上传文件,传入file-like object参数,示例代码如下:
f = open('/Users/michael/test.png', 'rb')
r = client.statuses.upload.post(status=u'测试OAuth 2.0带图片发微博', pic=f)
f.close() # APIClient不会自动关闭文件,需要手动关闭
请注意:上传的文件必须是file-like object,不能是str,因为无法区分一个str是文件还是字段。可以通过StringIO把一个str包装成file-like object
希望我的回答对你有帮助,望采纳。
python调用微博api的place接口出现10014错误,怎么解决
一:获取app-key 和 app-secret
使用自己的微博账号登录微博开放平台(http://open.weibo.com/),在微博开放中心下“创建应用”创建一个应用,应用信息那些随便填,填写完毕后,不需要提交审核,需要的只是那个app-key和app-secret
二:设置授权回调页
在“微博开放平台”的“管理中心”找到刚才创建的应用,点开这个应用,点开左边“应用信息”栏,会看见“App key”和“App Secret”的字样,这两个东西是要在后面程序中使用的。然后在“应用信息”下的“高级信息”点击“编辑”按钮,将“授权回调页面”设置为:https://api.weibo.com/oauth2/default.html,将“取消授权回调页”也设置为:https://api.weibo.com/oauth2/default.html。
三:安装微博 python SDK
有两种安装方式:
1:http://github.liaoxuefeng.com/sinaweibopy/下载新浪微博SDK
2:python有个简单的安装方式:直接在命令行下键入:
[python] view plain copy
sudo pip install sinaweibopy
四:实例验证,获取当前登录用户及其所关注(授权)用户的最新微博
这里需要注意的是在浏览器弹出一个页面,要先点击“授权”(这里进行的OAuth 2认证,我理解为就是用户访问我的应用后将页面导向新浪服务器然后用户输入信息到新浪服务器后授权给我的应用访问用户数据,这里我将的微博授权给下面的程序了),授权后浏览器中的URL类似:https://api.weibo.com/oauth2/default.html?code=2024222384d5dc88316d21675259d73a将code后面那个复制到控制端,程序需要读入2024222384d5dc88316d21675259d73a这个数据
注意:如果想获取别的信息,只需修改
[python] view plain copy
statuses = client.statuses__friends_timeline()['statuses']
中的 statuses__friends_timeline即可
[python] view plain copy
# -*- coding: utf-8 -*-
from weibo import APIClient
import webbrowser #python内置的包
APP_KEY = 'xxxxxxxx'#注意替换这里为自己申请的App信息
APP_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
CALLBACK_URL = 'https://api.weibo.com/oauth2/default.html'#回调授权页面
#利用官方微博SDK
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
#得到授权页面的url,利用webbrowser打开这个url
url = client.get_authorize_url()
print url
webbrowser.open_new(url)
#获取code=后面的内容
print '输入url中code后面的内容后按回车键:'
code = raw_input()
#code = your.web.framework.request.get('code')
#client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
r = client.request_access_token(code)
access_token = r.access_token # 新浪返回的token,类似abc123xyz456
expires_in = r.expires_in
# 设置得到的access_token
client.set_access_token(access_token, expires_in)
#可以打印下看看里面都有什么东西
statuses = client.statuses__friends_timeline()['statuses'] #获取当前登录用户以及所关注用户(已授权)的微博</span
length = len(statuses)
print length
#输出了部分信息
for i in range(0,length):
print u'昵称:'+statuses[i]['user']['screen_name']
print u'简介:'+statuses[i]['user']['description']
print u'位置:'+statuses[i]['user']['location']
print u'微博:'+statuses[i]['text']
结果如下(截取部分数据):
以下为我的关注用户的微博:
拿上边代码为例,这里我们获取的信息有:
求解答新浪微博api报错
系统级错误代码
错误代码 错误信息 详细描述
10001 System error 系统错误
10002 Service unavailable 服务暂停
10003 Remote service error 远程服务错误
10004 IP limit IP限制不能请求该资源
10005 Permission denied, need a high level appkey 该资源需要appkey拥有授权
10006 Source paramter (appkey) is missing 缺少source (appkey) 参数
10007 Unsupport mediatype (%s) 不支持的MediaType (%s)
10008 Param error, see doc for more info 参数错误,请参考API文档
10009 Too many pending tasks, system is busy 任务过多,系统繁忙
10010 Job expired 任务超时
10011 RPC error RPC错误
10012 Illegal request 非法请求
10013 Invalid weibo user 不合法的微博用户
10014 Insufficient app permissions 应用的接口访问权限受限
10016 Miss required parameter (%s) , see doc for more info 缺失必选参数 (%s),请参考API文档
10017 Parameter (%s)’s value invalid, expect (%s) , but get (%s) , see doc for more info 参数值非法,需为 (%s),实际为 (%s),请参考API文档
10018 Request body length over limit 请求长度超过限制
10020 Request api not found 接口不存在
10021 HTTP method is not suported for this request 请求的HTTP METHOD不支持,请检查是否选择了正确的POST/GET方式
10022 IP requests out of rate limit IP请求频次超过上限
10023 User requests out of rate limit 用户请求频次超过上限
10024 User requests for (%s) out of rate limit 用户请求特殊接口 (%s) 频次超过上限
服务级错误代码
错误代码 错误信息 详细描述
20001 IDs is null IDs参数为空
20002 Uid parameter is null Uid参数为空
20003 User does not exists 用户不存在
20005 Unsupported image type, only suport JPG, GIF, PNG 不支持的图片类型,仅仅支持JPG、GIF、PNG
20006 Image size too large 图片太大
20007 Does multipart has image 请确保使用multpart上传图片
20008 Content is null 内容为空
20009 IDs is too many IDs参数太长了
20012 Text too long, please input text less than 140 characters 输入文字太长,请确认不超过140个字符
20013 Text too long, please input text less than 300 characters 输入文字太长,请确认不超过300个字符
20014 Param is error, please try again 安全检查参数有误,请再调用一次
20015 Account or ip or app is illgal, can not continue 账号、IP或应用非法,暂时无法完成此操作
20016 Out of limit 发布内容过于频繁
20017 Repeat content 提交相似的信息
20018 Contain illegal website 包含非法网址
20019 Repeat conetnt 提交相同的信息
20020 Contain advertising 包含广告信息
20021 Content is illegal 包含非法内容
20022 Your ip’s behave in a comic boisterous or unruly manner 此IP地址上的行为异常
20031 Test and verify 需要验证码
20032 Update success, while server slow now, please wait 1-2 minutes 发布成功,目前服务器可能会有延迟,请耐心等待1-2分钟
- - -
20101 Target weibo does not exist 不存在的微博
20102 Not your own weibo 不是你发布的微博
20103 Can’t repost yourself weibo 不能转发自己的微博
20104 Illegal weibo 不合法的微博
20109 Weibo id is null 微博ID为空
20111 Repeated weibo text 不能发布相同的微博
- - -
20201 Target weibo comment does not exist 不存在的微博评论
20202 Illegal comment 不合法的评论
20203 Not your own comment 不是你发布的评论
20204 Comment id is null 评论ID为空
- - -
20301 Can’t send direct message to user who is not your follower 不能给不是你粉丝的人发私信
20302 Illegal direct message 不合法的私信
20303 Not your own direct message 不是属于你的私信
20305 Direct message does not exist 不存在的私信
20306 Repeated direct message text 不能发布相同的私信
20307 Illegal direct message id 非法的私信ID
- - -
20401 Domain not exist 域名不存在
20402 Wrong verifier Verifier错误
- - -
20501 Source_user or target_user does not exists 参数source_user或者target_user的用户不存在
20502 Please input right target user id or screen_name 必须输入目标用户id或者screen_name
20503 Need you follo
w user_id 参数user_id必须是你关注的用户
20504 Can not follow yourself 你不能关注自己
20505 Social graph updates out of rate limit 加关注请求超过上限
20506 Already followed 已经关注此用户
20507 Verification code is needed 需要输入验证码
20508 According to user privacy settings,you can not do this 根据对方的设置,你不能进行此操作
20509 Private friend count is out of limit 悄悄关注个数到达上限
20510 Not private friend 不是悄悄关注人
20511 Already followed privately 已经悄悄关注此用户
20512 Please delete the user from you blacklist before you follow the user 你已经把此用户加入黑名单,加关注前请先解除
20513 Friend count is out of limit! 你的关注人数已达上限
20521 Hi Superman, you have concerned a lot of people, have a think of how to make other people concern about you! ! If you have any questions, please contact Sina customer service: 400 690 0000 hi 超人,你今天已经关注很多喽,接下来的时间想想如何让大家都来关注你吧!如有问题,请联系新浪客服:400 690 0000
20522 Not followed 还未关注此用户
20523 Not followers 还不是粉丝
20524 Hi Superman, you have cancelled concerning a lot of people, have a think of how to make other people concern about you! ! If you have any questions, please contact Sina customer service: 400 690 0000 hi 超人,你今天已经取消关注很多喽,接下来的时间想想如何让大家都来关注你吧!如有问题,请联系新浪客服:400 690 0000
- - -
20601 List name too long, please input text less than 10 characters 列表名太长,请确保输入的文本不超过10个字符
20602 List description too long, please input text less than 70 characters 列表描叙太长,请确保输入的文本不超过70个字符
20603 List does not exists 列表不存在
20604 Only the owner has the authority 不是列表的所属者
20605 Illegal list name or list description 列表名或描叙不合法
20606 Object already exists 记录已存在
20607 DB error, please contact the administator 数据库错误,请联系系统管理员
20608 List name duplicate 列表名冲突
20610 Does not support private list 目前不支持私有分组
20611 Create list error 创建列表失败
20612 Only support private list 目前只支持私有分组
20613 You hava subscriber too many lists 订阅列表达到上限
20614 Too many lists, see doc for more info 创建列表达到上限,请参考API文档
20615 Too many members, see doc for more info 列表成员上限,请参考API文档
- - -
20701 Repeated tag text 不能提交相同的收藏标签
20702 Tags is too many 最多两个收藏标签
20703 Illegal tag name 收藏标签名不合法
- - -
20801 Trend_name is null 参数trend_name是空值
20802 Trend_id is null 参数trend_id是空值
- - -
20901 Error: in blacklist 错误:已经添加了黑名单
20902 Error: Blacklist limit has been reached. 错误:已达到黑名单上限
20903 Error: System administrators can not be added to the blacklist. 错误:不能添加系统管理员为黑名单
20904 Error: Can not add yourself to the blacklist. 错误:不能添加自己为黑名单
20905 Error: not in blacklist 错误:不在黑名单中
- - -
21001 Tags parameter is null 标签参数为空
21002 Tags name too long 标签名太长,请确保每个标签名不超过14个字符
- - -
21101 Domain parameter is error 参数domain错误
21102 The phone number has been used 该手机号已经被使用
21103 The account has bean bind phone 该用户已经绑定手机
21104 Wrong verifier Verifier错误
- - -
21301 Auth faild 认证失败
21302 Username or password error 用户名或密码不正确
21303 Username and pwd auth out of rate limit 用户名密码认证超过请求限制
21304 Version rejected 版本号错误
21305 Parameter absent 缺少必要的参数
21306 Parameter rejected OAuth参数被拒绝
21307 Timestamp refused 时间戳不正确
21308 Nonce used 参数nonce已经被使用
21309 Signature method rejected 签名算法不支持
21310<
/td Signature invalid 签名值不合法
21311 Consumer key unknown 参数consumer_key不存在
21312 Consumer key refused 参数consumer_key不合法
21313 Miss consumer key 参数consumer_key缺失
21314 Token used Token已经被使用
21315 Token expired Token已经过期
21316 Token revoked Token不合法
21317 Token rejected Token不合法
21318 Verifier fail Pin码认证失败
21319 Accessor was revoked 授权关系已经被解除
21320 OAuth2 must use https 使用OAuth2必须使用https
21321 Applications over the unaudited use restrictions 未审核的应用使用人数超过限制
21327 Expired token token过期
- - -
21501 Urls is null 参数urls是空的
21502 Urls is too many 参数urls太多了
21503 IP is null IP是空值
21504 Url is null 参数url是空值
- - -
21601 Manage notice error, need auth 需要系统管理员的权限
21602 Contains forbid world 含有敏感词
21603 Applications send notice over the restrictions 通知发送达到限制
- - -
21701 Manage remind error, need auth 提醒失败,需要权限
21702 Invalid category 无效分类
21703 Invalid status 无效状态码
- - -
21901 Geo code input error 地理信息输入错误
如何调用api发微博
什么微博平台?
国内现在只有新浪和腾讯开放了自己
新浪微博的api接口的微博API接口
新浪微博的api接口,其他的不可能用API了
新浪微博的api接口,只能模拟表单或者POST之类的。
新浪的官方API
新浪微博的api接口:http://open.weibo.com/wiki/%E9%A6%96%E9%A1%B5
腾讯的官方API:http://wiki.open.t.qq.com/index.php/API%E6%96%87%E6%A1%A3
关于新浪微博的api接口和新浪微博的api接口有哪些的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
新浪微博的api接口的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于新浪微博的api接口有哪些、新浪微博的api接口的信息别忘了在本站进行查找喔。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~