本文整理汇总了Java中com.restfb.Connection.getData方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.getData方法的具体用法?Java Connection.getData怎么用?Java Connection.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.restfb.Connection
的用法示例。
在下文中一共展示了Connection.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopRecentMessages
import com.restfb.Connection; //导入方法依赖的package包/类
@Override
public List<Message> getTopRecentMessages(User user) {
if (!isServiceEnabled(user)) {
return Collections.emptyList();
}
FacebookClient client = helper.getFacebookClient(user);
try {
Connection<Post> con = client.fetchConnection(OWN_FEED, Post.class, Parameter.with(LIMIT_PARAM, 100));
List<Post> posts = new ArrayList<Post>(con.getData());
for (Iterator<Post> it = posts.iterator(); it.hasNext();) {
Post post = it.next();
if (!((post.getLikes() != null && post.getLikes().getCount() != null && post.getLikes().getCount().longValue() > 0)
|| (post.getLikesCount() != null && post.getLikesCount().longValue() > 0))) {
it.remove();
}
}
List<Message> messages = helper.postsToMessages(posts, true, user.getFacebookSettings().getUserId(), client, false);
return messages;
} catch (FacebookException ex) {
handleException("Problem fetching recent top own messages", ex, user);
return Collections.emptyList();
}
}
示例2: calculateReputation
import com.restfb.Connection; //导入方法依赖的package包/类
private int calculateReputation(Connection<Post> con) {
int reputation = 0;
for (Post post : con.getData()) {
// likes weigh less than retweets and welshare likes, because they don't mean "share"
if (post.getLikesCount() != null) {
reputation += post.getLikesCount().intValue() * (Constants.LIKE_SCORE - 2);
} else if (post.getLikes() != null && post.getLikes().getCount() != null) {
reputation += post.getLikes().getCount().intValue() * (Constants.LIKE_SCORE - 2);
}
if (post.getComments() != null && post.getComments().getCount() != null) {
int commentCount = post.getComments().getCount().intValue();
commentCount = Math.min(commentCount, 7); //limit to 7 comments; not taking long discussion into account
reputation += commentCount * Constants.REPLY_SCORE;
}
}
return reputation;
}
示例3: getIdsOfFilteredFriends
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* Filter string, which will be used for filtering of users by "contains" rule.
*
* <p>
* For example: You have 3 friends on Facebook with names: "John Woo", "Marc Boo", "Susie Cole" and filter will be "oo" Then
* output of this method will return "John Woo" and "Marc Boo"
* </p>
*
* @param filter Filter string, which will be used for filtering of users by "contains" rule. For example
* @return ids of filtered friends
*/
public List<String> getIdsOfFilteredFriends(String filter) throws PortletException, IOException {
// Not good to obtain all friends within each request, but we don't have better way atm (limitation of facebook search
// api...)
Connection<NamedFacebookType> connection = this.fetchConnection("me/friends", NamedFacebookType.class);
if (connection == null) {
return new ArrayList<String>();
}
List<NamedFacebookType> allFriends = connection.getData();
List<String> result = new ArrayList<String>();
for (NamedFacebookType current : allFriends) {
if (current.getName().contains(filter)) {
result.add(current.getId());
}
}
return result;
}
示例4: getLikers
import com.restfb.Connection; //导入方法依赖的package包/类
@Override
public List<User> getLikers(String externalMessageId, User user) {
if (!isServiceEnabled(user)) {
return Collections.emptyList();
}
String facebookId = getFacebookId(externalMessageId);
FacebookClient client = helper.getFacebookClient(user);
try {
Connection<com.restfb.types.User> conn = client.fetchConnection(facebookId + "/likes", com.restfb.types.User.class);
List<com.restfb.types.User> data = conn.getData();
List<User> users = new ArrayList<User>(data.size());
for (com.restfb.types.User fbLiker : data) {
User liker = new User();
helper.fillUserData(liker, fbLiker);
users.add(liker);
}
return users;
} catch (FacebookException e) {
handleException("Problem getting likers of a message with id " + facebookId, e, user);
return Collections.emptyList();
}
}
示例5: getMyFriends
import com.restfb.Connection; //导入方法依赖的package包/类
@Deprecated
public List<FacebookProfile> getMyFriends() {
Connection<User> myFriends = apiConnection.fetchConnection("me/friends", User.class);
List<User> friendsList = myFriends.getData();
List<String> todo = new ArrayList<String>();
List<FacebookProfile> result = new ArrayList<FacebookProfile>();
for (User friend : friendsList) {
todo.add(friend.getId());
}
Collection<FacebookProfile> value = this.getUserFromThreadedAPI(todo);
for (FacebookProfile val : value) {
result.add(val);
}
return result;
}
示例6: getPageOfFriends
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* get Page of friends according to given offset and limit
*
* @param offset
* @param limit
* @return friends starting from offset and number of returned friends will be limit
*/
public List<NamedFacebookType> getPageOfFriends(int offset, int limit) throws PortletException, IOException {
Connection<NamedFacebookType> con = this.fetchConnection("me/friends", NamedFacebookType.class,
Parameter.with("offset", offset), Parameter.with("limit", limit));
if (con != null) {
return con.getData();
} else {
return new ArrayList<NamedFacebookType>();
}
}
示例7: getStatusesOfPerson
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* return FacebookUserBean with filled status messages
*
* @param friendId
* @param myId This parameter is used only to recognize Facebook scope, which we need
* @param accessToken
* @return FacebookUserBean with filled status messages
*/
public FacebookUserBean getStatusesOfPerson(String friendId, String myId, AccessToken accessToken) throws PortletException,
IOException {
Connection<StatusMessage> statusMessageConnection = this.fetchConnection(friendId + "/statuses", StatusMessage.class,
Parameter.with("limit", 5));
if (statusMessageConnection == null) {
return null;
}
List<StatusMessage> statuses = statusMessageConnection.getData();
FacebookUserBean ffb = new FacebookUserBean();
ffb.setId(friendId);
ffb.setScope(false);
ffb.setStatuses(statuses);
if (statuses.size() == 0) {
// Different scope is needed for me and different for my friends
String neededScope = friendId.equals(myId) ? "user_status" : "friends_status";
if (accessToken.isScopeAvailable(neededScope)) {
ffb.setScope(true);
} else {
ffb.setNeededScope(neededScope);
}
} else {
NamedFacebookType currentFriendToDisplay = this.fetchObject(friendId, NamedFacebookType.class,
Parameter.with("fields", "id,name"));
if (currentFriendToDisplay != null) {
ffb.setName(currentFriendToDisplay.getName());
}
}
return ffb;
}
示例8: getMessages
import com.restfb.Connection; //导入方法依赖的package包/类
private Future<List<Message>> getMessages(User user, Message lastMessage, String connection) {
if (!isServiceEnabled(user)) {
return SocialUtils.emptyFutureList();
}
FacebookClient client = helper.getFacebookClient(user);
try {
Parameter[] params;
if (lastMessage != null) {
params = new Parameter[2];
params[1] = Parameter.with("until", lastMessage.getDateTime()
.getMillis() / DateTimeConstants.MILLIS_PER_SECOND - 1);
} else {
params = new Parameter[1];
}
params[0] = Parameter.with(LIMIT_PARAM, messagesPerFetch);
Connection<Post> con = client.fetchConnection(connection, Post.class, params);
List<Post> result = con.getData();
if (result.isEmpty()) {
return SocialUtils.emptyFutureList();
}
List<Message> messages = helper.postsToMessages(result,
user.getFacebookSettings().isFetchImages(),
user.getFacebookSettings().getUserId(), client);
return SocialUtils.wrapMessageList(messages);
} catch (FacebookException ex) {
handleException("Problem with getting messages from facebook", ex, user);
return SocialUtils.emptyFutureList();
}
}
示例9: getFriends
import com.restfb.Connection; //导入方法依赖的package包/类
@Override
@SqlReadonlyTransactional
public List<UserDetails> getFriends(User user) {
if (!isServiceEnabled(user)) {
return Collections.emptyList();
}
FacebookClient client = helper.getFacebookClient(user);
try {
Connection<com.restfb.types.User> friends = client.fetchConnection("me/friends", com.restfb.types.User.class);
List<com.restfb.types.User> friendsList = friends.getData();
List<UserDetails> userDetails = new ArrayList<UserDetails>(friendsList.size());
for (com.restfb.types.User friend : friendsList) {
User wsUser = dao.getByPropertyValue(User.class, "facebookSettings.userId", friend.getId());
if (wsUser != null) {
UserDetails details = new UserDetails(wsUser);
userDetails.add(details);
}
}
logger.debug("Fetched " + userDetails.size() + " friends from facebook that are registered on welshare");
return userDetails;
} catch (FacebookException e) {
handleException("Problem getting facebook friends", e, user);
return Collections.emptyList();
}
}
示例10: importMessages
import com.restfb.Connection; //导入方法依赖的package包/类
@Override
public void importMessages(User user) {
if (!isServiceEnabled(user) || !user.getFacebookSettings().isImportMessages()) {
return;
}
try {
FacebookClient client = helper.getBackgroundFacebookClient(user);
Parameter[] params = new Parameter[2];
params[0] = Parameter.with(LIMIT_PARAM, 100);
params[1] = Parameter.with("since", user.getFacebookSettings().getLastImportedMessageTime() / DateTimeConstants.MILLIS_PER_SECOND + 1);
Connection<Post> con = client.fetchConnection(OWN_FEED, Post.class, params);
List<Post> posts = con.getData();
if (posts.size() == 0) {
return;
}
List<Message> messages = helper.postsToMessages(posts,
user.getFacebookSettings().isFetchImages(),
user.getFacebookSettings().getUserId(), null);
helper.importExternalMessages(user, messages);
} catch (FacebookException e) {
handleException("Problem importing facebook messages for user " + user , e, user);
}
}
示例11: getFriends
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* Returns a List of Friends for a given owner
*
* @param facebookClient The client object used to retrieve data from facebook
* @param owner The owner object which represents the user for which data is to be downloaded
* @return Returns a List of Friends for a given owner
*/
List<Friend> getFriends(FacebookClient facebookClient, Owner owner) {
Connection<User> friends = facebookClient.fetchConnection("me/friends", User.class);
List<Friend> friendList = new ArrayList<Friend>();
logger.info("Found {} friends.", friends.getData().size());
for(User facebookFriend: friends.getData()) {
Friend friend = new Friend();
friend.setFacebookID(facebookFriend.getId());
friend.setFacebookName(facebookFriend.getName());
friendList.add(friend);
}
return friendList;
}
示例12: validatePermission
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* Check user's permissions.
*
* @param accessToken Access token
* @throws PermissionException Permission not found
*/
public void validatePermission(String accessToken) throws PermissionException {
FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
Connection<JsonObject> dataList = facebookClient.fetchConnection("me/permissions", JsonObject.class);
boolean installed = false;
boolean email = false;
boolean publishStream = false;
boolean readStream = false;
for (JsonObject data : dataList.getData()) {
if (data.optInt("installed") == 1) {
installed = true;
}
if (data.optInt("email") == 1) {
email = true;
}
if (data.optInt("publish_stream") == 1) {
publishStream = true;
}
if (data.optInt("read_stream") == 1) {
readStream = true;
}
}
if (!installed) {
throw new PermissionException("Permission not found: installed");
}
if (!email) {
throw new PermissionException("Permission not found: email");
}
if (!publishStream) {
throw new PermissionException("Permission not found: publish_stream");
}
if (!readStream) {
throw new PermissionException("Permission not found: read_stream");
}
}
示例13: run
import com.restfb.Connection; //导入方法依赖的package包/类
void run() {
User user = facebookClient.fetchObject("me", User.class);
System.out.println(user);
Connection<User> friends = facebookClient.fetchConnection("me/friends", User.class);
for(User friend: friends.getData()) {
System.out.println(friend.getName());
System.out.println("\t"+friend.getId());
System.out.println("\t"+friend.getType());
System.out.println("\t"+friend.getVerified());
}
}
示例14: generateAll
import com.restfb.Connection; //导入方法依赖的package包/类
public static void generateAll(FacebookClient fbc, Facebook facebook, File coreFile, ArrayList<String> skipAlbums, long maxAlbumpics)
{
File dir = coreFile.getParentFile();
CustomStringBuilder builder = new CustomStringBuilder("|");
Properties listProps = new Properties();
File userFile = new File("" + dir + "/user.xml");
User user = fbc.fetchObject("me", User.class, MasterParameter.getParameterByClass(User.class));
userInfo(user, fbc, facebook, true, true, userFile);
// the Graph API only returns friends who are using this app, so it is
// useless to fetch them
Connection<Album> albums = fbc.fetchConnection("me/albums", Album.class, MasterParameter.getParameterByClass(Album.class));
ArrayList<Album> albumList = new ArrayList<>(albums.getData());
Connection<Photo> photos = fbc.fetchConnection("me/photos", Photo.class, MasterParameter.getParameterByClass(Photo.class));
Album lonelyAlbum = new Album();
lonelyAlbum.setName("Einzelbilder");
lonelyAlbum.setDescription("Fotos ohne Album");
if (photos.getData().size() >= 1)
lonelyAlbum.setCoverPhoto(photos.getData().get(0).getId());
lonelyAlbum.setId("lonely");
albumList.add(lonelyAlbum);
for (Album album : albumList)
{
if (!skipAlbums.contains(album.getName()))
{
File albumXml = new File("" + dir + "/albums/" + album.getId() + "/albuminfo.xml");
builder.append(FileUtils.getWayTo(dir, albumXml));
albumInfo(album, fbc, albumXml, maxAlbumpics, album.getId().equalsIgnoreCase("lonely"), photos);
}
}
listProps.put(PropertyFile.ALBUMS.toString(), builder.toString());
builder.empty();
Connection<Post> posts = fbc.fetchConnection("me/posts", Post.class, MasterParameter.getParameterByClass(Post.class));
for (Post post : posts.getData())
{
File postXml = new File("" + dir + "/posts/" + post.getId() + "/postinfo.xml");
builder.append(FileUtils.getWayTo(dir, postXml));
postInfo(post, postXml, fbc);
}
listProps.put(PropertyFile.POSTS.toString(), builder.toString());
builder.empty();
for (String pageToken : facebook.pages().fetchAllAccessTokens().values())
{
FacebookClient fc = new DefaultFacebookClient(pageToken, Version.VERSION_2_3);
Page page = fc.fetchObject("me", Page.class, MasterParameter.getParameterByClass(Page.class));
File pageXml = new File("" + dir + "/pages/" + page.getId() + "/pageinfo.xml");
builder.append(FileUtils.getWayTo(dir, pageXml));
pageInfo(page, pageXml);
}
listProps.put(PropertyFile.PAGES.toString(), builder.toString());
builder.empty();
Connection<Group> groups = fbc.fetchConnection("me/groups", Group.class, MasterParameter.getParameterByClass(Group.class));
for (Group group : groups.getData())
{
File groupXml = new File("" + dir + "/groups/" + group.getId() + "/groupinfo.xml");
builder.append(FileUtils.getWayTo(dir, groupXml));
groupInfo(group, fbc, groupXml);
}
listProps.put(PropertyFile.GROUPS.toString(), builder.toString());
listProps.put(PropertyFile.USER.toString(), FileUtils.getWayTo(coreFile, userFile));
writeProperties(listProps, coreFile, "list of all xml files");
}
示例15: resetDB
import com.restfb.Connection; //导入方法依赖的package包/类
/**
* Removes a previously registered subscription having the specified
* subscriptionID.
*/
@RequestMapping(value = "/Admin/ResetDB", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<?> resetDB(@RequestParam String userID, @RequestParam String accessToken) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("Content-Type", "text/html; charset=utf-8");
// Access Control is not mandatory
// However, if fid and accessToken provided, more information provided
FacebookClient fc = null;
List<String> friendList = null;
if (userID != null) {
// Check accessToken
fc = OAuthUtil.isValidatedFacebookClient(accessToken, userID);
if (fc == null) {
return new ResponseEntity<>(new String("Unauthorized Token"), responseHeaders, HttpStatus.UNAUTHORIZED);
}
friendList = new ArrayList<String>();
Connection<User> friendConnection = fc.fetchConnection("me/friends", User.class);
for (User friend : friendConnection.getData()) {
friendList.add(friend.getId());
}
}
// OAuth Fails
if (!OAuthUtil.isAdministratable(userID, friendList)) {
Configuration.logger.log(Level.INFO, " No right to administration ");
return new ResponseEntity<>(new String("No right to administration"), responseHeaders,
HttpStatus.BAD_REQUEST);
}
if (Configuration.mongoDatabase.getCollection("EventData") != null) {
Configuration.mongoDatabase.getCollection("EventData").drop();
}
if (Configuration.mongoDatabase.getCollection("MasterData") != null) {
Configuration.mongoDatabase.getCollection("MasterData").drop();
}
Configuration.logger.log(Level.INFO, " Repository Initialized ");
return new ResponseEntity<>(new String("All Event/Master Data removed"), responseHeaders, HttpStatus.OK);
}