腾讯微博OAuth web认证
来源:互联网 发布:审批流软件 编辑:程序博客网 时间:2024/06/05 23:56
在腾讯开放平台网站下载javaSDK,修改OAuth.java中的app和appsecret,导出jar包。
userServlet的dopost方法
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub WebOAuth weboauth=new WebOAuth(); try { OAuth oauth=weboauth.getRequestToken(); request.getSession().setAttribute("oauth", oauth);// weboauth.getAccessToken(); String url = "http://open.t.qq.com/cgi-bin/authorize?oauth_token=" + oauth.getOauth_token(); response.sendRedirect(url); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
CallBackServlet的dopost方法。在获取授权之后跳转到这个servlet上,然后再这个servlet上做一些处理。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("1******************************"); WebOAuth weboauth=new WebOAuth(); System.out.println("2***********************************"); OAuthClient auth=new OAuthClient(); System.out.println("3********************************************"); OAuth oauth=(OAuth)request.getSession().getAttribute("oauth"); System.out.println("4*****************************************************"); oauth.setOauth_verifier(request.getParameter("oauth_verifier")); System.out.println("5***************************************************************"); try { oauth=auth.accessToken(oauth); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("-----------------"); System.out.println(oauth.getOauth_token()); System.out.println(oauth.getOauth_token_secret()); response.sendRedirect("http://t.qq.com/"); }
//WebOAuth类package server; import com.tencent.weibo.beans.OAuth;import com.tencent.weibo.utils.OAuthClient; public class WebOAuth { public com.tencent.weibo.beans.OAuth oauth=new com.tencent.weibo.beans.OAuth("http://localhost:8080/liecheshikebiao_qq/CallBackServlet"); OAuthClient auth=new OAuthClient(); public OAuth getRequestToken() throws Exception{ oauth = auth.requestToken(oauth); if (oauth.getStatus() == 1) { System.out.println("Get Request Token failed!"); return null; } else { String oauth_token = oauth.getOauth_token(); return oauth; } } public void getAccessToken() throws Exception{ oauth = auth.accessToken(oauth); }}
- 腾讯微博OAuth web认证
- OAuth认证介绍及腾讯微博OAuth认证示例
- 腾讯微博(一)Oauth认证
- 腾讯微博项目 2 之Oauth认证
- 腾讯微博项目 之Oauth认证2
- Android腾讯微博之1.0 Oauth认证
- 四大微博OAuth认证
- 新浪微博Oauth认证
- 四大微博OAuth认证
- 新浪微博OAuth认证
- 新浪微博OAuth认证
- 1.腾讯微博Android客户端开发——OAuth认证介绍
- 1.腾讯微博Android客户端开发——OAuth认证介绍
- 腾讯微博Android客户端开发——OAuth认证介绍
- 腾讯微博Android客户端开发——OAuth认证介绍
- 1.腾讯微博Android客户端开发——OAuth认证介绍
- 新浪、腾讯、网易、搜狐微博OAuth认证整合Android版
- 实现了新浪、腾讯、网易、搜狐四大微博的统一OAuth认证、调用接口。
- Pinyin 拼音转换工具类
- 归并排序
- Windows系统调用架构分析—也谈KiFastCallEntry函数地址的获取
- A星
- Mixing Milk USACO
- 腾讯微博OAuth web认证
- Handler&Looper
- Qwt源码解读之QwtClipper 类
- HDOJ 1114 Piggy-Bank (多重背包)
- 数据库实验
- 详解CoreAnimation中如何自定义动画属性
- 矩阵快速幂 poj3070 3233 3735 3150
- 动态链接技术
- Linux下Sed命令用法详解