新浪微博网站接入开发(渣浪的api写的骗人,不用urlencoding!!!!!!)

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    try {
				
			String urlNameString = "https://api.weibo.com/oauth2/access_token";
			String code =request.getParameter("code");
			//可以使用部分用户权限的token,可以使网站代替用户操作的关键认证
		    AccessToken accessToken=null; 
	        // 根据地址获取请求
		  	HttpPost request2 = new HttpPost(urlNameString);//这里发送get请求
	        //  封装参数
		  	List<NameValuePair> params=new ArrayList<NameValuePair>();
		  	params.add(new BasicNameValuePair("client_id", "你的client_id"));
		  	params.add(new BasicNameValuePair("client_secret", "你的clien_secret"));
		  	params.add(new BasicNameValuePair("redirect_uri", "http://TestDemoYR/reverse.action"));
		  	params.add(new BasicNameValuePair("grant_type", "authorization_code"));
		  	params.add(new BasicNameValuePair("code","CODE"));
		  	request2.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
		  	//发送请求获取响应,这里response主要的作用是获取token
		  	HttpResponse response2=new DefaultHttpClient().execute(request2);
		  	//通过oauth获取AccessToken
		    Oauth oauth = new Oauth();
		    accessToken =oauth.getAccessTokenByCode(code);
		    
		    //此处就可以通过token发送文章了!
		    Timeline timeline = new Timeline("2.00d3BzZFbEVFoCf372edcac6NulR9E");
			Status status = timeline.updateStatus("用程序发微博");
			
			
		
			Log.logInfo(status.toString());
		} catch (WeiboException e1) {
			e1.printStackTrace();
		}
     
       
             
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值