Example #1
0
 public String authorize(String response_type) throws WeiboException {
   return WeiboConfig.getValue("authorizeURL").trim()
       + "?client_id="
       + WeiboConfig.getValue("client_ID").trim()
       + "&redirect_uri="
       + WeiboConfig.getValue("redirect_URI").trim()
       + "&response_type="
       + response_type;
 }
Example #2
0
 public AccessToken getAccessTokenByCode(String code) throws WeiboException {
   Log.logInfo(
       "@(︶︿︶)@:第三方应用使用httpclient模拟浏览器向Provider发出http请求,当Consumer从Provider获得AccessToken时再通过AccessToken来发微博。");
   return new AccessToken(
       Weibo.client.post(
           WeiboConfig.getValue("accessTokenURL"),
           new PostParameter[] {
             new PostParameter("client_id", WeiboConfig.getValue("client_ID")),
             new PostParameter("client_secret", WeiboConfig.getValue("client_SERCRET")),
             new PostParameter("grant_type", "authorization_code"),
             new PostParameter("code", code),
             new PostParameter("redirect_uri", WeiboConfig.getValue("redirect_URI"))
           },
           false));
 }
Example #3
0
 public JSONObject getUserTimelineIdsByName(String screen_name) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/user_timeline/ids.json",
           new PostParameter[] {new PostParameter("screen_name", screen_name)})
       .asJSONObject();
 }
Example #4
0
 /**
  * 获取指定微博的转发微博列表
  *
  * @param id 需要查询的微博ID
  * @param count 单页返回的记录条数,默认为50
  * @param page 返回结果的页码,默认为1
  * @return list of Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a
  *     href="http://open.weibo.com/wiki/2/statuses/repost_timeline">statuses/repost_timeline</a>
  * @since JDK 1.5
  */
 public StatusWapper getRepostTimeline(String id, Paging page) throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/repost_timeline.json",
           new PostParameter[] {new PostParameter("id", id)},
           page));
 }
Example #5
0
 public StatusWapper getFriendsTimeline(Integer feature, Paging paging) throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/friends_timeline.json",
           new PostParameter[] {new PostParameter("feature", feature.toString())},
           paging));
 }
Example #6
0
 /**
  * 上传图片并发布一条新微博
  *
  * @param status 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字
  * @param pic 要上传的图片,仅支持JPEG、GIF、PNG格式,图片大小小于5M。
  * @return Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/upload">statuses/upload</a>
  * @since JDK 1.5
  */
 public Status UploadStatus(String status, ImageItem item) throws WeiboException {
   return new Status(
       client.multPartURL(
           WeiboConfig.getValue("baseURL") + "statuses/upload.json",
           new PostParameter[] {new PostParameter("status", status)},
           item));
 }
Example #7
0
 /**
  * 更新当前登录用户所有收藏下的指定标签
  *
  * @param id 需要更新的标签ID。
  * @return update tags of Favorites status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a
  *     href="http://open.weibo.com/wiki/2/favorites/tags/update_batch">favorites/tags/update_batch</a>
  * @since JDK 1.5
  */
 public JSONObject updateFavoritesTagsBatch(String tid, String tag) throws WeiboException {
   return Weibo.client
       .post(
           WeiboConfig.getValue("baseURL") + "favorites/tags/update_batch.json",
           new PostParameter[] {new PostParameter("tid", tid), new PostParameter("tag", tag)})
       .asJSONObject();
 }
Example #8
0
  /*
   * 解析站内应用post的SignedRequest split为part1和part2两部分
   */
  public String parseSignedRequest(String signed_request)
      throws IOException, InvalidKeyException, NoSuchAlgorithmException {
    String[] t = signed_request.split("\\.", 2);
    // 为了和 url encode/decode 不冲突,base64url 编码方式会将
    // '+','/'转换成'-','_',并且去掉结尾的'='。 因此解码之前需要还原到默认的base64编码,结尾的'='可以用以下算法还原
    int padding = (4 - t[0].length() % 4);
    for (int i = 0; i < padding; i++) t[0] += "=";
    String part1 = t[0].replace("-", "+").replace("_", "/");

    SecretKey key =
        new SecretKeySpec(WeiboConfig.getValue("client_SERCRET").getBytes(), "hmacSHA256");
    Mac m;
    m = Mac.getInstance("hmacSHA256");
    m.init(key);
    m.update(t[1].getBytes());
    String part1Expect = BASE64Encoder.encode(m.doFinal());

    sun.misc.BASE64Decoder decode = new sun.misc.BASE64Decoder();
    String s = new String(decode.decodeBuffer(t[1]));
    if (part1.equals(part1Expect)) {
      return ts(s);
    } else {
      return null;
    }
  }
Example #9
0
 /**
  * 根据标签获取当前登录用户该标签下的收藏列表
  *
  * @param tid
  * @param page
  * @return list of the favorite Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/favorites/show">favorites/show</a>
  * @since JDK 1.5
  */
 public List<Favorites> getFavoritesByTags(String tid, Paging page) throws WeiboException {
   return Favorites.constructFavorites(
       Weibo.client.get(
           WeiboConfig.getValue("baseURL") + "favorites/by_tags.json",
           new PostParameter[] {new PostParameter("tid", tid)},
           page));
 }
Example #10
0
 /**
  * 批量获取用户的粉丝数、关注数、微博数
  *
  * @param uids 需要获取数据的用户UID,多个之间用逗号分隔,最多不超过100个
  * @return jsonobject
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/users/domain_show">users/domain_show</a>
  * @since JDK 1.5
  */
 public JSONArray getUserCount(String uids) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "users/counts.json",
           new PostParameter[] {new PostParameter("uids", uids)})
       .asJSONArray();
 }
Example #11
0
 /**
  * 获取某个用户最新发表的微博列表ID
  *
  * @return user_timeline IDS
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/statuses/user_timeline">statuses/user_timeline</a>
  * @since JDK 1.5
  */
 public JSONObject getUserTimelineIdsByUid(String uid) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/user_timeline/ids.json",
           new PostParameter[] {new PostParameter("uid", uid)})
       .asJSONObject();
 }
Example #12
0
 /**
  * 获取指定微博的转发微博列表
  *
  * @param id 需要查询的微博ID
  * @return ids
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a
  *     href="http://open.weibo.com/wiki/2/statuses/repost_timeline/ids">statuses/repost_timeline/ids</a>
  * @since JDK 1.5
  */
 public JSONObject getRepostTimelineIds(String id) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/repost_timeline/ids.json",
           new PostParameter[] {new PostParameter("id", id)})
       .asJSONObject();
 }
Example #13
0
 /**
  * 通过个性化域名获取用户资料以及用户最新的一条微博
  *
  * @param domain 需要查询的个性化域名。
  * @return User
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/users/domain_show">users/domain_show</a>
  * @since JDK 1.5
  */
 public User showUserByDomain(String domain) throws WeiboException {
   return new User(
       client
           .get(
               WeiboConfig.getValue("baseURL") + "users/domain_show.json",
               new PostParameter[] {new PostParameter("domain", domain)})
           .asJSONObject());
 }
Example #14
0
 /**
  * 根据用户ID获取用户信息
  *
  * @param uid 需要查询的用户ID
  * @return User
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/users/show">users/show</a>
  * @since JDK 1.5
  */
 public User showUserById(String uid) throws WeiboException {
   return new User(
       client
           .get(
               WeiboConfig.getValue("baseURL") + "users/show.json",
               new PostParameter[] {new PostParameter("uid", uid)})
           .asJSONObject());
 }
Example #15
0
 /**
  * 返回最新的公共微博
  *
  * @param count 单页返回的记录条数,默认为20。
  * @param baseApp 是否仅获取当前应用发布的信息。0为所有,1为仅本应用。
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/public_timeline">statuses/public_timeline
  *     </a>
  * @since JDK 1.5
  */
 public StatusWapper getPublicTimeline(int count, int baseApp) throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/public_timeline.json",
           new PostParameter[] {
             new PostParameter("count", count), new PostParameter("base_app", baseApp)
           }));
 }
Example #16
0
 /**
  * 获取微博官方表情的详细信息
  *
  * @param type 表情类别,face:普通表情、ani:魔法表情、cartoon:动漫表情,默认为face
  * @param language 语言类别,cnname:简体、twname:繁体,默认为cnname
  * @return Emotion
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/emotions">emotions</a>
  * @since JDK 1.5
  */
 public List<Emotion> getEmotions(String type, String language) throws WeiboException {
   return Emotion.constructEmotions(
       client.get(
           WeiboConfig.getValue("baseURL") + "emotions.json",
           new PostParameter[] {
             new PostParameter("type", type), new PostParameter("language", language)
           }));
 }
Example #17
0
 /**
  * 根据用户ID获取用户信息
  *
  * @param screen_name 用户昵称
  * @return User
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/users/show">users/show</a>
  * @since JDK 1.5
  */
 public User showUserByScreenName(String screen_name) throws WeiboException {
   return new User(
       client
           .get(
               WeiboConfig.getValue("baseURL") + "users/show.json",
               new PostParameter[] {new PostParameter("screen_name", screen_name)})
           .asJSONObject());
 }
Example #18
0
 /**
  * 通过微博ID获取其MID
  *
  * @param id 需要查询的微博ID,批量模式下,用半角逗号分隔,最多不超过20个。
  * @param type 获取类型,1:微博、2:评论、3:私信,默认为1。
  * @return Status's mid
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/querymid">statuses/querymid</a>
  * @since JDK 1.5
  */
 public JSONObject QueryMid(Integer type, String id) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/querymid.json",
           new PostParameter[] {
             new PostParameter("id", id), new PostParameter("type", type.toString())
           })
       .asJSONObject();
 }
Example #19
0
 public StatusWapper getBilateralTimeline(Integer base_app, Integer feature)
     throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/bilateral_timeline.json",
           new PostParameter[] {
             new PostParameter("base_app", base_app), new PostParameter("feature", feature)
           }));
 }
Example #20
0
 /**
  * 转发一条微博
  *
  * @param id 要转发的微博ID
  * @param status 添加的转发文本,必须做URLencode,内容不超过140个汉字,不填则默认为“转发微博”
  * @param is_comment 是否在转发的同时发表评论,0:否、1:评论给当前微博、2:评论给原微博、3:都评论,默认为0
  * @return Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/repost">statuses/repost</a>
  * @since JDK 1.5
  */
 public Status Repost(String id, String status, Integer is_comment) throws WeiboException {
   return new Status(
       client.post(
           WeiboConfig.getValue("baseURL") + "statuses/repost.json",
           new PostParameter[] {
             new PostParameter("id", id),
             new PostParameter("status", status),
             new PostParameter("is_comment", is_comment.toString())
           }));
 }
Example #21
0
 /**
  * 通过微博ID获取其MID
  *
  * @param id 需要查询的微博ID,批量模式下,用半角逗号分隔,最多不超过20个。
  * @param type 获取类型,1:微博、2:评论、3:私信,默认为1。
  * @param is_batch 是否使用批量模式,0:否、1:是,默认为0。
  * @return Status's mid
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/querymid">statuses/querymid</a>
  * @since JDK 1.5
  */
 public JSONObject QueryMid(Integer type, String id, int is_batch) throws WeiboException {
   return client
       .get(
           WeiboConfig.getWeiboInfo().getBaseUrl() + "statuses/querymid.json",
           new PostParameter[] {
             new PostParameter("id", id),
             new PostParameter("type", type.toString()),
             new PostParameter("is_batch", is_batch)
           })
       .asJSONObject();
 }
Example #22
0
 /**
  * 通过微博MID获取其ID
  *
  * @param mid true string 需要查询的微博MID,批量模式下,用半角逗号分隔,最多不超过20个
  * @param type 获取类型,1:微博、2:评论、3:私信,默认为1。
  * @return Status's id
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/queryid">statuses/queryid</a>
  * @since JDK 1.5
  */
 public JSONObject QueryId(String mid, Integer type, int isBase62) throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/queryid.json",
           new PostParameter[] {
             new PostParameter("mid", mid),
             new PostParameter("type", type.toString()),
             new PostParameter("isBase62", isBase62)
           })
       .asJSONObject();
 }
Example #23
0
 /**
  * 获取当前登录用户及其所关注用户的最新微博消息。<br>
  * 和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。
  *
  * @param paging 相关分页参数
  * @param 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
  * @return list of the Friends Timeline
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/statuses/friends_timeline">statuses/friends_timeline
  *     </a>
  * @since JDK 1.5
  */
 public StatusWapper getFriendsTimeline(Integer baseAPP, Integer feature, Paging paging)
     throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getWeiboInfo().getBaseUrl() + "statuses/friends_timeline.json",
           new PostParameter[] {
             new PostParameter("base_app", baseAPP.toString()),
             new PostParameter("feature", feature.toString())
           },
           paging));
 }
Example #24
0
 /**
  * 上传图片并发布一条新微博
  *
  * @param status 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字
  * @param pic 要上传的图片,仅支持JPEG、GIF、PNG格式,图片大小小于5M。
  * @param lat 纬度,有效范围:-90.0到+90.0,+表示北纬,默认为0.0。
  * @param long 经度,有效范围:-180.0到+180.0,+表示东经,默认为0.0。
  * @return Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/upload">statuses/upload</a>
  * @since JDK 1.5
  */
 public Status UploadStatus(String status, ImageItem item, Float lat, Float longs)
     throws WeiboException {
   return new Status(
       client.multPartURL(
           WeiboConfig.getWeiboInfo().getBaseUrl() + "statuses/upload.json",
           new PostParameter[] {
             new PostParameter("status", status),
             new PostParameter("lat", lat.toString()),
             new PostParameter("long", longs.toString())
           },
           item));
 }
Example #25
0
 /**
  * 删除当前登录用户所有收藏下的指定标签
  *
  * @param id 需要删除的标签ID。。
  * @return destroy tags of Favorites status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a
  *     href="http://open.weibo.com/wiki/2/favorites/tags/destroy_batch">favorites/tags/destroy_batch</a>
  * @since JDK 1.5
  */
 public Boolean destroyFavoritesTagsBatch(String ids) throws WeiboException {
   try {
     return Weibo.client
         .post(
             WeiboConfig.getValue("baseURL") + "favorites/destroy_batch.json",
             new PostParameter[] {new PostParameter("ids", ids)})
         .asJSONObject()
         .getBoolean("result");
   } catch (JSONException e) {
     throw new WeiboException(e);
   }
 }
Example #26
0
 public JSONObject getFriendsTimelineIds(Integer baseAPP, Integer feature, Paging paging)
     throws WeiboException {
   return client
       .get(
           WeiboConfig.getValue("baseURL") + "statuses/friends_timeline/ids.json",
           new PostParameter[] {
             new PostParameter("base_app", baseAPP.toString()),
             new PostParameter("feature", feature.toString())
           },
           paging)
       .asJSONObject();
 }
Example #27
0
 /**
  * 发布一条新微博
  *
  * @param status 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字
  * @param lat 纬度,有效范围:-90.0到+90.0,+表示北纬,默认为0.0。
  * @param long 经度,有效范围:-180.0到+180.0,+表示东经,默认为0.0。
  * @param annotations 元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息,每条微博可以包含一个或者多个元数据,
  *     必须以json字串的形式提交,字串长度不超过512个字符,具体内容可以自定
  * @return Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.0
  * @see <a href="http://open.weibo.com/wiki/2/statuses/update">statuses/update</a>
  * @since JDK 1.5
  */
 public Status UpdateStatus(String status, Float lat, Float longs, String annotations)
     throws WeiboException {
   return new Status(
       client.post(
           WeiboConfig.getValue("baseURL") + "statuses/update.json",
           new PostParameter[] {
             new PostParameter("status", status),
             new PostParameter("lat", lat.toString()),
             new PostParameter("long", longs.toString()),
             new PostParameter("annotations", annotations)
           }));
 }
Example #28
0
 /**
  * 获取某个用户最新发表的微博列表
  *
  * @param uid 需要查询的用户ID。
  * @param screen_name 需要查询的用户昵称。
  * @param count 单页返回的记录条数,默认为50。
  * @param page 返回结果的页码,默认为1。
  * @param base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
  * @param feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
  * @return list of the user_timeline
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/statuses/user_timeline">statuses/user_timeline</a>
  * @since JDK 1.5
  */
 public StatusWapper getUserTimelineByUid(
     String uid, Paging page, Integer base_app, Integer feature) throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getWeiboInfo().getBaseUrl() + "statuses/user_timeline.json",
           new PostParameter[] {
             new PostParameter("uid", uid),
             new PostParameter("base_app", base_app.toString()),
             new PostParameter("feature", feature.toString())
           },
           page));
 }
Example #29
0
 public StatusWapper getUserTimelineByName(
     String screen_name, Paging page, Integer base_app, Integer feature) throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/user_timeline.json",
           new PostParameter[] {
             new PostParameter("screen_name", screen_name),
             new PostParameter("base_app", base_app.toString()),
             new PostParameter("feature", feature.toString())
           },
           page));
 }
Example #30
0
 /**
  * 获取最新的提到登录用户的微博列表,即@我的微博
  *
  * @param count 单页返回的记录条数,默认为50。
  * @param page 返回结果的页码,默认为1。
  * @param filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
  * @param filter_by_source 来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。
  * @param filter_by_type 原创筛选类型,0:全部微博、1:原创的微博,默认为0。
  * @return list of Status
  * @throws WeiboException when Weibo service or network is unavailable
  * @version weibo4j-V2 1.0.1
  * @see <a href="http://open.weibo.com/wiki/2/statuses/mentions">statuses/mentions</a>
  * @since JDK 1.5
  */
 public StatusWapper getMentions(
     Paging page, Integer filter_by_author, Integer filter_by_source, Integer filter_by_type)
     throws WeiboException {
   return Status.constructWapperStatus(
       client.get(
           WeiboConfig.getValue("baseURL") + "statuses/mentions.json",
           new PostParameter[] {
             new PostParameter("filter_by_author", filter_by_author.toString()),
             new PostParameter("filter_by_source", filter_by_source.toString()),
             new PostParameter("filter_by_type", filter_by_type.toString())
           },
           page));
 }