关于新浪微博API应用的问题
我照这个帖子的步骤弄的,http://blog.csdn.net/zjl234/article/details/7303779#comments。但是没出现楼主说的输入新浪微博账号密码验证的步骤,直接出现的是访问出错的提示,也得不到code,之后也不知道怎么做了,哪位大牛知道问题出在哪了么? --------------------编程问答-------------------- 来人啊,很着急~ --------------------编程问答-------------------- 新浪授权有两种oauth1.0和2.0,我一直用的1.0,授权代码:
public void doGet(HttpServletRequest request, HttpServletResponse response){
System.setProperty("weibo4j.oauth.consumerKey", "xxx");
System.setProperty("weibo4j.oauth.consumerSecret","xxx");
System.setProperty("weibo4j.debug", "false");
RequestToken requestToken = getWeibo().getOAuthRequestToken("http://www.test.com/back/sina");
request.getSession(true).setAttribute("sinaweibo_req_auth",requestToken);
response.sendRedirect(requestToken.getAuthorizationURL();)
}
完成授权后回调:
public void doGet(HttpServletRequest request, HttpServletResponse response){
HttpSession objSession = request.getSession(true);
String verifier = request.getParameter("oauth_verifier");
RequestToken resToken = (RequestToken) objSession.getAttribute("sinaweibo_req_auth");
Weibo weibo = new Weibo();
AccessToken accessToken = weibo.getOAuthAccessToken(resToken.getToken(),resToken.getTokenSecret(), verifier);
objSession.removeAttribute("sinaweibo_req_auth");
long uid = objAccessToken.getUserId();
String strToken = objAccessToken.getToken();
String strSecret = objAccessToken.getTokenSecret();
//有了token和secret就可以调用新浪API了。
//查询用户信息
System.setProperty("weibo4j.oauth.consumerKey", "xxx");
System.setProperty("weibo4j.oauth.consumerSecret","xxx");
System.setProperty("weibo4j.debug", "false");
Weibo objWeibo = new Weibo();
User objUser = objWeibo.showUser(uid+"");
}
补充:Java , Java相关