SDK2/javasdk

跳转至: 导航搜索

目录

简介

renren-api2-sdk-java 是对人人 API 2.0 接口进行了一个简单封装,主要包括了 OAuth 2.0 认证、接口调用。

安装

有两种方式集成renren-api2-sdk-java:

  • 使用编译好的jar包;

下载最新的SDK包,将包中lib目录中的renren-api2-sdk-java.jar和commons-logging.jar添加到工程的类路径中即可。

  • 使用Maven依赖jar包;

下载最新的SDK包,使用Maven将SDK工程安装到本地(mvn install)库或发布(mvn deploy)到私有远程库。

注意:如果安装、发布过程中,测试用例无法通过,可以使用-Dmaven.test.skip=true选项跳过构建过程中测试阶段。例如:mvn install -Dmaven.test.skip=true。

安装或发布jar包以后,在pom.xml中添加依赖依赖:

<dependency> <groupId>com.renren.api</groupId> <artifactId>renren-api2-sdk</artifactId> <version>1.0-SNAPSHOT</version> </dependency>

使用说明

OAuth 2.0 认证

SDK支持所有的OAuth2.0授权流程。

  • 实例化RennClient:
RennClient client = new RennClient(API_KEY, SECRET_KEY);
  • 使用Authorization Code认证:
client.authorizeWithAuthorizationCode("adummycode", "http://www.renren.com/callback");
  • 使用Client Credentials认证:
client.authorizeWithClientCredentials();
  • 如果之前已经获得了Access Token,使用Access Token对象认证:
client.authorizeWithAccessToken(BEARER_ACCESS_TOKEN);
client.authorizeWithAccessToken(MAC_ACCESS_TOKEN);

至此已经完成了认证过程。

调用location API

LocationFeed [] locationfeed = client.getLocationService().listLocationFeed (Integer pageSize, Integer pageNumber, LocationFeedType locationFeedType, Integer radius, Double longitude, Double latitude)
Location location = client.getLocationService().getLocation (Boolean deflection, Double longitude, Double latitude)

调用album API

Album [] album = client.getAlbumService().listAlbum (Long ownerId, Integer pageSize, Integer pageNumber)
Album album = client.getAlbumService().getAlbum (Long albumId, Long ownerId)
Album album = client.getAlbumService().putAlbum (String location, String description, String name, AccessControl accessControl, String password)

调用blog API

  • 以分页的方式获取某个用户的日志列表 /v2/blog/list
Blog [] blog = client.getBlogService().listBlog (Long ownerId, Integer pageSize, Integer pageNumber)
Blog blog = client.getBlogService().putBlog (String title, AccessControl accessControl, String password, String content)
Blog blog = client.getBlogService().getBlog (Long ownerId, Long blogId, String password)

调用vipinfo API

VIPInfo vipinfo = client.getVipinfoService().getVipinfo (Long userId)

调用evaluation API

ReplyCheckinResponse replycheckinresponse = client.getEvaluationService().putEvaluationReply (String content, Long evaluationId, Long ownerId, Long reId)
ReplyEvaluation [] replyevaluation = client.getEvaluationService().listEvaluationReply (Long evaluationId, Long ownerId, Integer pageNo, Integer pageSize)
Long result = client.getEvaluationService().putEvaluation (String content, String placeId)

调用share API

  • 分享人人网内部UGC资源,例如:日志、照片、相册、分享(基于已有分享再次进行分享) /v2/share/ugc/put
Share share = client.getShareService().putShareUgc (Long ugcOwnerId, String comment, Long ugcId, UGCType ugcType)
Share [] share = client.getShareService().listShareHot (Integer pageSize, Integer pageNumber, ShareType shareType)
  • 分享人人网外部资源,例如:视频、图片等
    如果要分享一张本地照片到人人网(即上传),建议使用/v2/photo/upload接口 /v2/share/url/put
Share share = client.getShareService().putShareUrl (String comment, String url)
Share share = client.getShareService().getShare (Long shareId, Long ownerId)
Share [] share = client.getShareService().listShare (Long ownerId, Integer pageSize, Integer pageNumber)

调用ubb API

Ubb [] ubb = client.getUbbService().listUbb ()

调用notification API

Integer result = client.getNotificationService().putNotificationUser (String content, Long [] userIds)
Integer result = client.getNotificationService().putNotificationApp (String content, Long [] userIds)

调用feed API

  • 发送自定义新鲜事。新鲜事会发布用户的个人动态信息到用户人人网主页,
    同时会出现在好友的新鲜事中。 /v2/feed/put
Long result = client.getFeedService().putFeed (String message, String title, String actionTargetUrl, String imageUrl, String description, String subtitle, String actionName, String targetUrl)
Feed [] feed = client.getFeedService().listFeed (FeedType [] feedType, Long userId, Integer pageSize, Integer pageNumber)

调用invitation API

Invitation invitation = client.getInvitationService().putInvitation (InvitationType invitationType, Long userId, String img, String gitName, String url)

调用place API

LocationFeed [] locationfeed = client.getPlaceService().listPlaceFriendFeed (Integer pageNo, Integer pageSize)
SavePoiResponse savepoiresponse = client.getPlaceService().putPlace (String address, String name, Double longitude, Double latitude)
LocationFeed [] locationfeed = client.getPlaceService().listPlaceFeed (String placeId, Integer pageSize, Integer pageNumber, LocationFeedType locationFeedType)
Place [] place = client.getPlaceService().listPlace (Integer pageSize, Integer pageNumber, String placeName, Integer radius, Double longitude, Boolean deflection, Double latitude)

调用profile API

  • 获取用户的主页信息,包括各种统计数据。 /v2/profile/get
Profile profile = client.getProfileService().getProfile (Long userId)

调用app API

  • 获取某个应用的信息,部分信息取自缓存,不能立即生效 /v2/app/get
App app = client.getAppService().getApp ()

调用status API

Status status = client.getStatusService().getStatus (Long statusId, Long ownerId)
Status status = client.getStatusService().putStatus (String content)
Status [] status = client.getStatusService().listStatus (Long ownerId, Integer pageSize, Integer pageNumber)
Status status = client.getStatusService().shareStatus (String content, Long statusId, Long ownerId)

调用like API

Integer result = client.getLikeService().removeLikeUgc (Long ugcOwnerId, LikeUGCType likeUGCType, Long ugcId)
  • 赞人人内部资源,相册、照片、日志、分享、视频等。 /v2/like/ugc/put
Integer result = client.getLikeService().putLikeUgc (Long ugcOwnerId, LikeUGCType likeUGCType, Long ugcId)
LikeInfo likeinfo = client.getLikeService().getLikeUgcInfo (Integer limit, Boolean withLikeUsers, LikeUGCType likeUGCType, Long ugcId)

调用photo API

  • 上传照片至用户相册。此接口需要采用multipart/form-data的编码方式。 /v2/photo/upload
Photo photo = client.getPhotoService().uploadPhoto (Long albumId, String description, File file)
Photo photo = client.getPhotoService().getPhoto (Long albumId, Long photoId, Long ownerId, String password)
  • 以分页的方式获取某个用户某个相册里的照片列表 /v2/photo/list
Photo [] photo = client.getPhotoService().listPhoto (Long albumId, Long ownerId, Integer pageSize, Integer pageNumber, String password)

调用checkin API

ReplyCheckin [] replycheckin = client.getCheckinService().listCheckinReply (Integer pageNo, Integer pageSize, Long checkinId)
Long result = client.getCheckinService().putCheckin (String content, String placeId)
PoiCheckin poicheckin = client.getCheckinService().getCheckin (Long checkinId)
LocationFeed [] locationfeed = client.getCheckinService().listCheckin (Integer pageNo, Integer pageSize)
ReplyCheckinResponse replycheckinresponse = client.getCheckinService().putCheckinReply (String content, Long reId, Long checkinId)

调用comment API

  • 对某个对象(日志、状态、照片、相册、分享等)进行评论 /v2/comment/put
Comment comment = client.getCommentService().putComment (String content, Long targetUserId, CommentType commentType, Long entryOwnerId, Long entryId)
Comment [] comment = client.getCommentService().listComment (Boolean desc, Integer pageSize, Integer pageNumber, CommentType commentType, Long entryOwnerId, Long entryId)

调用user API

User [] user = client.getUserService().batchUser (Long [] userIds)
User user = client.getUserService().getUser (Long userId)
User [] user = client.getUserService().listUserFriend (Long userId, Integer pageSize, Integer pageNumber)
User [] user = client.getUserService().listUserFriendUninstall ()
User [] user = client.getUserService().listUserFriendMutual (Long userId)
User [] user = client.getUserService().listUserFriendApp ()
User user = client.getUserService().getUserLogin ()

调用friend API

Integer [] result = client.getFriendService().listFriend (Long userId, Integer pageSize, Integer pageNumber)