<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          weiboclient4j微博客戶端API

          聯(lián)合創(chuàng)作 · 2023-09-19 06:44

          為什么需要另外一個Java版本的微博客戶端?

          新浪微博官方推薦的Java客戶端 weibo4j 一直沒有發(fā)布到maven倉庫,而我們是重度maven用戶,因而重新發(fā)明了這個新的輪子。

          通過maven引用weiboclient4j

          在項目pom.xml里面加入依賴:

           com.github.hoverruan weiboclient4j 0.4.13

          使用

          Weiboclient4j支持新浪微博API V1和V2(未完成),目前推薦使用V2版本的接口:

          // 使用你的應用的api key和secret String apiKey = "xxxxxxx"; 
          String apiSecret = "xxxxxxxx"; 
          WeiboClient client = new WeiboClient(apiKey, apiSecret);

          OAuth2例子:

          String authorizationCallback = "..."; // 你的Callback地址 
          String state = "..."; 
          String url = client.getAuthorizationUrl(ResponseType.Code, DisplayType.Default, state, authorizationCallback); // 瀏覽器重定向到url; 用戶授權; 然后返回callback地址 
          String code = ... // 從新浪的回調請求里面獲得code String accessTokenCallback = "..."; // 或者Access Token的Callback地址 
          SinaWeibo2AccessToken accessToken = client.getAccessTokenByCode(code, accessTokenCallback); 
          System.out.println("Access token: " + accessToken.getToken()); 
          System.out.println("User Uid: " + accessToken.getUid()); 
          System.out.println("Expires in: " + accessToken.getExpiresIn()); 
          System.out.println("Remind in: " + accessToken.getRemindIn());

          獲取用戶Timeline例子:

          StatusService service = client.getStatusService(); 
          Timeline friendsTimeline = service.getFriendsTimeline();

          更多的使用例子可以參考 weiboclient4j.examples.OAuth2CommandLine

          API參數(shù)對象化

          WeiboClient里面,大部分的方法都沒有Javadoc,取而代之的是大部分的參數(shù)都是特定的對象,這樣做的原因是因為:

          • 寫Javadoc太麻煩

          • 一些API的參數(shù)較多,如果使用基本類型容易混淆各個參數(shù)的含義

          • IDE對已知類型的對象、Enum能提供更友好的提醒和自動完成

          所有的參數(shù)對象在 package weiboclient4j.params 下面;舉一個例子:

          使用靜態(tài)引入 CoreParameters.\*:

          import static weiboclient4j.params.CoreParameters.*; 
          FriendshipService service = client.getFriendshipService(); 
          Friendship friendship; 
          friendship = service.getFriendship(sourceUid(12345), targetUid(67890)); 
          // 或者 
          friendship = service.getFriendship(sourceScreenName("xxx"), targetScreenName("yyy"));

          使用 P:

          import weiboclient4j.params.P; 
          FriendshipService service = client.getFriendshipService(); 
          Friendship friendship; 
          friendship = service.getFriendship(P.sourceUid(12345), P.targetUid(67890)); 
          // 或者 
          friendship = service.getFriendship(P.sourceScreenName("xxx"), P.targetScreenName("yyy"));

          分頁對象 Paging

          分頁相關的參數(shù),全部通過 Paging 對象封裝:

          Paging paging = Paging.create() .sinceId(12345) .count(25); 
          Timeline timeline = service.getFriendsTimeline(paging, BaseApp.No, Feature.All); // 后兩個參數(shù)可省略

          新浪微博API V2支持情況

          API文檔 V2

          微博接口 StatusService 完成
          評論接口 CommentService 完成
          用戶接口 UserService 完成
          關系接口 FriendshipService 完成
          帳號接口 AccountService 完成
          收藏接口 FavoriteService 完成
          話題接口 TrendService 完成
          標簽接口 TagService 完成
          注冊接口 RegisterService 完成
          搜索接口 SearchService 完成
          推薦接口 SuggestionService 完成
          提醒接口 RemindService 完成
          短鏈接口 ShortUrlService 完成
          通知接口 NotificationService 完成
          公共服務接口 CommonService 完成
          位置服務接口 PlaceService 完成
          地理信息接口 LocationService 開發(fā)中

           

          瀏覽 24
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  成人网大香蕉五月视频 | 日日碰夜夜 | 国产亚洲欧美在线 | 亚洲视频网站在线 | 免费一级性爱电影 |