模拟登录获取新浪微博的access_token
public static AccessToken refreshToken(){
Properties props = new Properties();
try {
props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("sina_account.properties"));
String url = props.getProperty("url");/*模拟登录的地址, https://api.weibo.com/oauth2/authorize*/
PostMethod postMethod = new PostMethod(url);
postMethod.addParameter("client_id", props.getProperty("client_id"));//your client id
postMethod.addParameter("redirect_uri", props.getProperty("redirect_uri"));//your url
postMethod.addParameter("userId", props.getProperty("userId"));//需要获取微薄的use id
postMethod.addParameter("passwd", props.getProperty("passwd"));
postMethod.addParameter("isLoginSina", "0");
postMethod.addParameter("action", "submit");
postMethod.addParameter("response_type", props.getProperty("response_type"));//code
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("Referer", "https://api.weibo.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_redirect_url&from=sina&response_type=code"));//伪造referer
headers.add(new Header("Host", "api.weibo.com"));
headers.add(new Header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0"));
HttpClient client = new HttpClient();
client.getHostConfiguration().getParams().setParameter("http.default-headers", headers);
client.executeMethod(postMethod);
int status = postMethod.getStatusCode();
if(status != 302){
LOG.error("refresh token failed");
return null;
}
Header location = postMethod.getResponseHeader("Location");
if(location != null){
String retUrl = location.getValue();
int begin = retUrl.indexOf("code=");
if(begin != -1){
int end = retUrl.indexOf("&", begin);
if(end == -1)
end = retUrl.length();
String code = retUrl.substring(begin+5, end);
if(code != null){
AccessToken token = oauth.getAccessTokenByCode(code);
Oauth oauth = new Oauth();
return token;
}
}
}
} catch (FileNotFoundException e) {
LOG.error("error" + e);
} catch (IOException e) {
LOG.error("error" + e);
}
LOG.error("refresh token failed");
return null;
}
模拟登录获取新浪微博的access_token相关推荐
- java模拟登录获取Cookie
关于java模拟登录获取Cookie时经历的坑 springboot 引入jar包版本 通过httpclient来模拟登录 代码部分 表单提交部分代码(未测试正确与否,只是找了前辈们的东西过来) 总结 ...
- python 模拟登录获取cookie_Python获取新浪微博cookie模拟登录
这次尝试模拟登录微博,获取com网站cookie,cn不可用. 分析网站 首先打开weibo.com微博登录页面,如果已经登录需要先退出(其他的com登录页应该也是可以的). 打开chrome调试,查 ...
- python模拟登录页面下载_Python爬虫实战入门四:使用Cookie模拟登录——获取电子书下载链接...
在实际情况中,很多网站的内容都是需要登录之后才能看到,如此我们就需要进行模拟登录,使用登录后的状态进行爬取.这里就需要使用到Cookie. 现在大多数的网站都是使用Cookie跟踪用户的登录状态,一旦 ...
- python模拟登记获取cookie_Python爬虫实战入门四:使用Cookie模拟登录——获取电子书下载链接...
在实际情况中,很多网站的内容都是需要登录之后才能看到,如此我们就需要进行模拟登录,使用登录后的状态进行爬取.这里就需要使用到Cookie. 使用Cookie进行模拟登录 现在大多数的网站都是使用Coo ...
- python模拟登录获取Cookie
在自动化处理过程中,有些操作往往需要登录之后才能进一步操作,所以我们需要通过登录获取到cookies信息,因为登录信息一般都是保存到cookies当中的,我们只需要在登录完成后把请求返回的cookie ...
- python爬虫登录下载_Python爬虫实战入门四:使用Cookie模拟登录——获取电子书下载链接...
在实际情况中,很多网站的内容都是需要登录之后才能看到,如此我们就需要进行模拟登录,使用登录后的状态进行爬取.这里就需要使用到Cookie. 现在大多数的网站都是使用Cookie跟踪用户的登录状态,一旦 ...
- scrapy淘宝爬虫(通过模拟登录获取cookie)获取价格信息评论
项目要求:爬取淘宝某领域下的商品名称,价格,评论. (我贼怂,如果阿里巴巴的朋友发现,请联系我,我立刻删帖,谢谢.) 一.构思流程 模拟登陆 获取cookie scrapy爬取数据 二.分步分析 (一 ...
- 微信公众号模拟登录,获取公众号历史链接
好久没写博客啦,这次写一下最近的一个好玩的. 大家有时看到一个公众号觉得特别好玩,想看它所有的以前的链接咋办?从手机端挨个翻啊...太费劲了不是? 所以我就想从公众号里是不是有这东西能获取,果然被俺发 ...
- php 提取登录QQsid_php模拟登录qq邮箱(curl命令详解)
header("Content-type:text/html;charset=utf-8"); $cookie_file = dirname(__FILE__)."/co ...
最新文章
- 关于使用JAVA中JDK安装和在命令行中编译和运行程序的一些总结
- Define and Publish Platform Events
- XML和实体类之间相互转换(序列化和反序列化)
- 2022最新软件设计师历年真题和答案解析分享!
- Glide圆角和centerCrop()的那些坑
- linux hping3命令,Linux中hping3命令起什么作用呢?
- 三年经验前端vue面试记录
- LEGION: Visually compare modeling techniques for regression
- 《数字化决策》连载 | 七:探索并建立决策模型(3)
- 华为手机长按图片无法下载
- web开发表情包---微信表情
- 基于MediaPipe API实现骨骼识别
- window.print 打印文章时设置字体及解决每页跨页截断问题
- 厦门大学计算机英语考试,【图片】一战厦大计算机上岸,经验帖。慢更【考研吧】_百度贴吧...
- php批量添加水印图片大小,解析php中两种缩放图片的函数,为图片添加水印
- linux让前台程序脱离终端运行
- 如何挑选视频会议摄像头?
- slam第六讲_g2o
- 【MySQL】单表访问之索引合并
- jedis模糊删除key
热门文章
- Navicat premium 12 连接Oracle ORA-21561: OID generation failed
- 飞桨“国货之光”助力青年学者科研,百度与CCF联合发布松果基金
- weiphp数据模型设置
- 矩母函数(Moment Generating Function)
- 计算机毕业设计Java客户关系管理平台(源码+mysql数据库+系统+lw文档)
- android:ellipsize属性说明
- java当线程离开临界区时_第2章 - 作业部落 Cmd Markdown 编辑阅读器
- c语言中sign的用法,Excel教程中sign函数用法和实例详解
- 什么是内联元素(行内)
- Java字符串中分隔符的字符串和数组的转换