您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)怎么使用java代碼獲取新浪微博應(yīng)用的access token代碼,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
具體內(nèi)容如下
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/oauth3/access_token"); String request = "https://api.weibo.com/oauth3/access_token?client_id=3921363495&client_secret=bac53e1f9c1e66514cf7410e39d581dd" + "&grant_type=authorization_code&code=7420036e360713bab82f62a5275aaba7&redirect_uri=https://api.weibo.com/oauth3/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/oauth3/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的特點(diǎn)有哪些 1.Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,實(shí)現(xiàn)了面向?qū)ο罄碚?,允許程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。 2.Java具有簡單性、面向?qū)ο?、分布式、安全性、平臺(tái)獨(dú)立與可移植性、動(dòng)態(tài)性等特點(diǎn)。 3.使用Java可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等。
關(guān)于“怎么使用java代碼獲取新浪微博應(yīng)用的access token代碼”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。