新浪微博API(java版)

來源:互聯網
上載者:User

新浪微博API(java版)
============================
修改事項:
1、介面返回結果採用json對象方式封裝
2、修改WeiboResponse中Null 字元串("")調用判斷的bug
3、修改了JSONObject中返回Null 物件的問題
4、增加了直接檔案上傳介面直接

常用介面執行個體:
(使用前先修改 Weibo.java 中
  public static final String CONSUMER_KEY = "";
 public static final String CONSUMER_SECRET = "";
 填寫成實際申請的 CONSUMER_KEY 及 CONSUMER_SECRET)

1、擷取最新公用微博列表
 參考:weibo4j.examples.GetTimelines 中的getPublicTimeline()部分

2、發表微博
 參考:weibo4j.examples.Update 中的updateStatus(...)部分

3、發表評論
 參考:weibo4j.examples.Update 中的updateComment(...)部分

4、刪除評論
 參考:weibo4j.examples.Update 中的destroyComment(...)部分

5、發送私人訊息
 參考:weibo4j.examples.DirectMessage 類

6、發錶帶圖片的微博
 參考:weibo4j.examples.OAuthUploadByFile 中的uploadStatus(status,file)部分

7、更新帳戶圖片
 參考:weibo4j.examples.OAuthUpdateProfile類

8、OAuth案頭應用訪問
 步驟: 1> 在weibo4j.examples.OAuthUpdate 訪問認證的URL,得到pin
    2> 在weibo4j.examples.OAuthUpdate  輸入pin,然後得到AccessToken
    3> 即可訪問使用者的微博,參考:weibo4j.examples.OAuthUpdateTwo

9、OAuth WEB應用訪問
 步驟:
     1> 在weibo4j.examples.WebOAuth 帶backurl參數請求OAuth認證,獲得RequestToken
      2> 在callback 的地址裡面,接受到oauth_verifier參數,然後再發一次請求,即可獲得AccessToken
      3> 用AccessToken訪問使用者的微博
 執行個體說明:
 
  在web目錄下面有兩個jsp頁面:
  call.jsp
     是發送request的請求,在第九行的參數“http://localhost:8080/callback.jsp”是回調地址
      當擷取成功後將RequestToken置入session,並重新導向到使用者認證地址
   callback.jsp
      接收到oauth_verifier參數,從session裡面拿到RequestToken,再請求擷取AccessToken
       擷取到後即可對使用者微博進行操作,本例中是發表微博
 
 測試環境:
  
  本例中可以將call.jsp和  callback.jsp直接放到tomcat的根目錄下面:webapps/ROOT
  並將執行個體項目編譯好的classes檔案和lib目錄拷貝到ROOT/WEB-INF下面
  重啟tomcat,訪問http://localhost:8080/call.jsp?opt=1 
 註:也可以打成war包,但注意call.jsp裡面的callback參數需要做相應修改

=============================================================================
其他介面在weibo4j.Weibo類中定義,調用方式請參考weibo4j.examples,下面是完整的介面列表:

擷取下行資料集(timeline)介面  方法名:
statuses/public_timeline 最新公用微博      方法名:getPublicTimeline
statuses/friends_timeline 最新關注人微博 (別名: statuses/home_timeline)  方法名:getFriendsTimeline
statuses/user_timeline 使用者發表微博列表   方法名:getUserTimeline(String id, Paging paging)
statuses/mentions 最新 @使用者的    方法名: getMentions()
statuses/comments 單條評論列表(按微博)   方法名:getComments()

微博提供者
statuses/show 擷取單條   方法名:showStatus(long id)

statuses/update 發表微博   方法名:updateStatus(String status)
statuses/upload 發表微博及圖片 方法名:uploadStatus(String status,File file)
statuses/destroy 刪除 方法名: destroyStatus(long statusId)

statuses/comment 評論 方法名: destroyComment(long commentId)
statuses/comment_destroy 刪除評論  方法名:destroyComment

私信介面
direct_messages 我的私信列表 方法名:getDirectMessages() 分頁 getDirectMessages(Paging paging)
direct_messages/sent 我發送的私信列表 方法名:getSentDirectMessages()
direct_messages/new 發送私信 方法名:sendDirectMessage(String id,String text)
direct_messages/destroy 刪除一條私信 方法名:destroyDirectMessage(int id)
關注介面
friendships/create 關注某使用者 方法名:createFriendship(String id)或 createFriendship(String id, boolean follow)
friendships/destroy 取消追蹤 方法名: destroyFriendship(String id)
friendships/exists 是否關注某使用者 方法名:existsFriendship(String userA, String userB)

friends/ids 關注列表 方法名: getFriendsIDs(long cursor)
followers/ids 粉絲列表 方法名:getFollowersIDs(long cursor)
帳號介面
account/verify_credentials 驗證身份是否合法 方法名:verifyCredentials()
account/rate_limit_status 查看當前頻率限制 方法名:rateLimitStatus()

account/update_profile_image 更改頭像 方法名:updateProfileImage(File image)
account/update_profile 更改資料 方法名:User updateProfile(String name, String email, String url, String location, String description)

收藏介面
favorites 收藏列表 方法名:getFavorites()
favorites/create 添加收藏 方法名:createFavorite(long id)
favorites/destroy 刪除收藏 方法名:destroyFavorite(long id)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.