当前位置: 首页>>代码示例>>Java>>正文


Java Connection类代码示例

本文整理汇总了Java中com.restfb.Connection的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Connection类属于com.restfb包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMessagesOfUser

import com.restfb.Connection; //导入依赖的package包/类
@Override
public List<Message> getMessagesOfUser(String externalId, User user) {
    if (!isServiceEnabled(user)) {
        return Collections.emptyList();
    }

    FacebookClient client = helper.getFacebookClient(user);

    try {
        Connection<Post> posts = client.fetchConnection(getFacebookId(externalId) + "/feed", Post.class);
        return helper.postsToMessages(posts.getData(), true, user.getFacebookSettings().getUserId(), client, false);
    } catch (FacebookException ex) {
        handleException("Problem getting friends of user " + externalId, ex, user);
        return Collections.emptyList();
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:17,代码来源:FacebookService.java

示例2: 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();
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:27,代码来源:FacebookService.java

示例3: 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;
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:19,代码来源:FacebookService.java

示例4: collectFeed

import com.restfb.Connection; //导入依赖的package包/类
private Connection<Post> collectFeed(String pagename) {
	
	AccessToken accessToken = new DefaultFacebookClient(Version.VERSION_2_3).obtainAppAccessToken(ConfigurationObject.MY_APP_ID, ConfigurationObject.MY_APP_SECRET);
	FacebookClient facebookClient23 = new DefaultFacebookClient(accessToken.getAccessToken(), Version.VERSION_2_3);

	//User user = facebookClient23.fetchObject("me", User.class);
	Page page = facebookClient23.fetchObject(pagename, Page.class, Parameter.with("fields","name,id, picture, likes"));
	return  facebookClient23.fetchConnection(page.getId()+"/feed", Post.class, Parameter.with("fields", "comments, full_picture")); //message,picture, likes, from,
}
 
开发者ID:chenav,项目名称:orufeo,代码行数:10,代码来源:FacebookBoImpl.java

示例5: processLikes

import com.restfb.Connection; //导入依赖的package包/类
public void processLikes(String objectId) {
    // Likes are processed for each object (post or comment). A like is represented
    // by an edge from the user to the object.
    Connection<User> userPages = client.fetchConnection(objectId + "/likes", User.class);
    for (List<User> users : userPages) {
        for (User user : users) {
            Process userProcess = getUserVertex(user.getId());

            if(userProcess == null){
                continue;
            }
            Artifact post = (Artifact) objects.get(objectId);
            WasGeneratedBy wgb = new WasGeneratedBy(post, userProcess);
            wgb.addAnnotation("fbType", "like");
            putEdge(wgb);
        }
    }
}
 
开发者ID:ashish-gehani,项目名称:SPADE,代码行数:19,代码来源:Facebook.java

示例6: 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;
}
 
开发者ID:exo-samples,项目名称:docs-samples,代码行数:29,代码来源:FacebookClientWrapper.java

示例7: 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();
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:27,代码来源:FacebookService.java

示例8: SearchFacebookPages

import com.restfb.Connection; //导入依赖的package包/类
public void SearchFacebookPages(String queryPar, Integer PageSize) {
	Connection<Page> publicSearch;
	if (queryPar != null) {
		resultPages = new ArrayList();
		facebookClient = new DefaultFacebookClient();
		publicSearch = facebookClient.fetchConnection("search", Page.class,
				Parameter.with("q", queryPar),
				Parameter.with("type", "page"),
				Parameter.with("limit", PageSize));

		for (int i = 0; i < publicSearch.getData().size(); i++) {
			if (publicSearch.getData().get(i).getName() != null) {
				resultPages.add(new FacebookPageData(publicSearch.getData()
						.get(i)));
			}
		}

	}

}
 
开发者ID:SmartSearch,项目名称:Edge-Node,代码行数:21,代码来源:FacebookDriver.java

示例9: search

import com.restfb.Connection; //导入依赖的package包/类
void search() {
  out.println("* Searching connections *");

  Connection<Post> publicSearch =
      facebookClient.fetchConnection("search", Post.class, Parameter.with("q", "watermelon"),
        Parameter.with("type", "post"));

  Connection<User> targetedSearch =
      facebookClient.fetchConnection("me/home", User.class, Parameter.with("q", "Mark"),
        Parameter.with("type", "user"));

  if (publicSearch.getData().size() > 0)
    out.println("Public search: " + publicSearch.getData().get(0).getMessage());

  out.println("Posts on my wall by friends named Mark: " + targetedSearch.getData().size());
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:17,代码来源:GraphReaderExample.java

示例10: getAlbums

import com.restfb.Connection; //导入依赖的package包/类
/**
 * Gets a User's album
 *
 * @param id user id
 */
private void getAlbums(String id) {
    Connection<Album> albums = client.fetchConnection(id + "/albums", Album.class);
    Iterator<List<Album>> iterator = albums.iterator();        
    int no_pics = 0;
    while(iterator.hasNext()){
        List<Album> data = iterator.next();
        this.noAlbums+=data.size();
        for (Album al : data) {
        if (al.getCount() != null) {
            this.noPictures += al.getCount();
        }
    }
    }                              
    
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:21,代码来源:FcbkCrawler.java

示例11: 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;
}
 
开发者ID:fabiogermann,项目名称:zhaw-facepath,代码行数:21,代码来源:FacebookFacade.java

示例12: testGetMessageTags

import com.restfb.Connection; //导入依赖的package包/类
@Test
public void testGetMessageTags() {
    Connection<PageMessageTag> connection = mock(Connection.class);
    when(connection.getData()).thenReturn(new ArrayList<PageMessageTag>());
    when(facebookClient.fetchConnection(PAGE_MESSAGE_TAGS_PATH, PageMessageTag.class)).thenReturn(connection);
    messenger.getMessageTags();
    verify(facebookClient).fetchConnection(PAGE_MESSAGE_TAGS_PATH, PageMessageTag.class);
}
 
开发者ID:marsbits,项目名称:restfbmessenger,代码行数:9,代码来源:DefaultMessengerTests.java

示例13: launch

import com.restfb.Connection; //导入依赖的package包/类
@Override
public boolean launch(String arguments) {
    MY_ACCESS_TOKEN = arguments;
    Runnable facebookProcessor = new Runnable() {
        @Override
        public void run() {
            // Start by fetching the user's own posts first. Posts include statuses,
            // links, photos, videos. Once the user's own posts are completely processed,
            // the reporter will iteratively fetch posts for the user's friends.
            client = new DefaultFacebookClient(MY_ACCESS_TOKEN);
            User me = client.fetchObject("me", User.class);
            String myId = me.getId();
            Process myVertex = getUserVertex(myId);
            processUserPhotos(myId);
            processUserPosts(myId);
            Connection<User> myFriends = client.fetchConnection("me/friends", User.class);

            for (List<User> myFriend : myFriends) {
                for (User friend : myFriend) {
                    String friendId = friend.getId();
                    Process friendVertex = getUserVertex(friendId);
                    WasTriggeredBy wtb = new WasTriggeredBy(friendVertex, myVertex);
                    putEdge(wtb);
                    processUserPosts(friendId);
                    processUserPhotos(friendId);
                }
            }
        }
    };
    Thread facebookThread = new Thread(facebookProcessor, "Facebook-Thread");
    facebookThread.start();

    return true;
}
 
开发者ID:ashish-gehani,项目名称:SPADE,代码行数:35,代码来源:Facebook.java

示例14: processComments

import com.restfb.Connection; //导入依赖的package包/类
public void processComments(String objectId) {
    // Comments will belong to a post so in addition to having an edge to the author
    // of the comment, there will be an edge to the parent post as well. Finally, the
    // comment may have likes which are handled in the processLikes() method.
    Connection<Comment> commentPages = client.fetchConnection(objectId + "/comments", Comment.class);

    for (List<Comment> comments : commentPages) {
        for (Comment comment : comments) {
            String fromUserId = comment.getFrom().getId();
            Process userProcess = getUserVertex(fromUserId);

            if(userProcess == null){
                continue;
            }

            Artifact commentArtifact = new Artifact();
            commentArtifact.addAnnotation("objectId", comment.getId());
            commentArtifact.addAnnotation("author", userProcess.getAnnotation("name"));
            commentArtifact.addAnnotation("message", comment.getMessage());
            commentArtifact.addAnnotation("time", comment.getCreatedTime().toString());
            commentArtifact.addAnnotation("fbType", "comment");
            objects.put(comment.getId(), commentArtifact);
            putVertex(commentArtifact);

            WasGeneratedBy wgb = new WasGeneratedBy(commentArtifact, userProcess);
            wgb.addAnnotation("fbType", "comment");
            putEdge(wgb);

            WasDerivedFrom wdf = new WasDerivedFrom(commentArtifact, (Artifact) objects.get(objectId));
            wdf.addAnnotation("fbType", "commentParent");
            putEdge(wdf);

            processLikes(comment.getId());
        }
    }
}
 
开发者ID:ashish-gehani,项目名称:SPADE,代码行数:37,代码来源:Facebook.java

示例15: 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>();
    }
}
 
开发者ID:exo-samples,项目名称:docs-samples,代码行数:17,代码来源:FacebookClientWrapper.java


注:本文中的com.restfb.Connection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。