android新浪微博調用使用者微博介面

來源:互聯網
上載者:User

根據上篇認證通過後,可以調用API中的開放介面. 一般我們開發的應用都是要顯示一些企業的微博資訊,如我之前開發的“萬事達卡”顯示萬事達人微博.

 首先我們要調用一個介面:http://api.t.sina.com.cn/statuses/user_timeline.json等同於現在的http://api.t.sina.com.cn/statuses/user_timeline.json 
 現在新浪都改成帶s的介面了,不過感覺還是不帶s好用,網上很多例子都是調用不帶s的,我調用了帶s的不管用,不知道原因,知道的朋友,請您給小弟說下. 這裡我也用不帶是的.

我們要注意一點:

 

一般我們都是根據screen_name設定查詢微博的.

 

程式碼片段:

OAuthConsumer authConsumer = new CommonsHttpOAuthConsumer( Oauth.consumerKey, Oauth.consumerSecret);  authConsumer.setTokenWithSecret(User.token, User.tokenSecret);這裡也可以把前面我們Oauth認證時候的authConsumer傳過來,就不用這些步驟了, client = new DefaultHttpClient();  httpPost = new HttpPost(USER_TIMELINE_URL);  // 把相應的屬性值穿進去 還有很多屬性,page,count等,請查看api.  List<NameValuePair> list = new ArrayList<NameValuePair>();  list.add(new BasicNameValuePair("screen_name", "萬事達人"));    httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));  httpPost.getParams().setBooleanParameter(    CoreProtocolPNames.USE_EXPECT_CONTINUE, false);  authConsumer.sign(httpPost);  httpResponse = client.execute(httpPost);  if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {   String result = EntityUtils.toString(httpResponse.getEntity());   Log.i(Oauth.TAG, result);  }

 

 這樣我們就可以擷取到我們要的微博資訊

 

展示如下:(顯示的是萬事達人)

                              

   正在開發中,樣子很醜,沒有來得及調整,就將就著吧.

 


 

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.