使用java代码获取新浪微博应用的access token代码实例
作者:JerryWangSAP 时间:2023-12-01 20:18:30
本文实例为大家分享了java代码获取新浪微博应用的access token的具体代码,供大家参考,具体内容如下
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
public class WeiboAccessTokenRequest
{
static public void main(String[] arg)
{
//System.setProperty("http.proxyHost", "proxy.wdf.diablo.corp");
//System.setProperty("http.proxyPort", "8080");
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost();
URI url;
try
{
//url = new URI("https://api.weibo.com/oauth2/access_token");
String request = "https://api.weibo.com/oauth2/access_token?client_id=3921363495&client_secret=bac53e1f9c1e66514cf7410e39d581dd"
+ "&grant_type=authorization_code&code=7420036e360713bab82f62a5275aaba7&redirect_uri=https://api.weibo.com/oauth2/default.html";
url = new URI(request);
post.setURI(url);
HttpHost proxy = new HttpHost("proxy.wdf.sap.corp", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
/*post.addHeader("client_id", "3921363495");
post.addHeader("client_secret", "bac53e1f9c1e66514cf7410e39d581dd");
post.addHeader("grant_type", "authorization_code");
post.addHeader("code", "7420036e360713bab82f62a5275aaba7");
post.addHeader("redirect_uri", "https://api.weibo.com/oauth2/default.html");*/
HttpResponse response = httpclient.execute(post);
HttpEntity entity = response.getEntity();
if (entity == null)
{
System.out.println("response is null!");
return;
}
InputStream instreams = entity.getContent();
String str = convertStreamToString(instreams);
System.out.println("Do something");
System.out.println(str);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
以上所述是小编给大家介绍的java代码获取新浪微博应用的access token实例详解整合网站的支持!
来源:https://blog.csdn.net/i042416/article/details/89818762
标签:java,新浪微博,Accesstoken
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
不知道面试会不会问Lambda怎么用(推荐)
2021-07-27 21:37:30
Android中ImageView的使用方法
2023-11-19 02:03:41
![](https://img.aspxhome.com/file/2023/4/108244_0s.jpg)
Java基础之位运算知识总结
2022-09-10 17:48:43
![](https://img.aspxhome.com/file/2023/3/66043_0s.png)
使用IDEA开发配置Java Web的初始化过程
2022-09-25 16:33:38
![](https://img.aspxhome.com/file/2023/4/64794_0s.jpg)
Java中将base64编码字符串转换为图片的代码
2023-07-14 12:23:51
Android实现波浪球效果
2021-09-02 16:07:53
![](https://img.aspxhome.com/file/2023/4/99794_0s.jpg)
Android学习之使用SharedPreferences存储应用程序数据
2023-09-09 14:00:41
![](https://img.aspxhome.com/file/2023/0/138920_0s.jpg)
Android图片三级缓存策略(网络、本地、内存缓存)
2022-08-06 01:28:19
![](https://img.aspxhome.com/file/2023/1/137361_0s.png)
Android应用创建多个快捷方式
2022-10-08 11:26:00
Java StringUtils字符串分割转数组的实现
2023-07-19 12:43:37
浅谈React Native打包apk的坑
2022-07-26 05:44:28
![](https://img.aspxhome.com/file/2023/7/139297_0s.jpg)
java导出数据库的全部表到excel
2023-11-25 09:38:33
java8新特性 stream流的方式遍历集合和数组操作
2023-03-29 10:49:25
![](https://img.aspxhome.com/file/2023/0/60790_0s.jpg)
用Kotlin实现Android点击事件的方法
2023-01-16 15:56:03
android intent使用定义标题
2023-11-07 07:06:17
java制作复制文件工具代码分享
2022-08-05 05:30:22
详解Spring 中 Bean 对象的存储和取出
2023-08-06 02:42:46
![](https://img.aspxhome.com/file/2023/2/57832_0s.png)
Java URL自定义私有网络协议
2021-08-11 02:21:06
![](https://img.aspxhome.com/file/2023/1/85871_0s.png)
Kotlin修饰符lateinit(延迟初始化)案例详解
2023-08-22 08:21:56
![](https://img.aspxhome.com/file/2023/8/122048_0s.png)
Java 详解垃圾回收与对象生命周期
2022-01-21 02:54:43