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


Java FacebookException类代码示例

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


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

示例1: getMessageByExternalId

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
@Cacheable(value="singleExternalMessageCache", key="#externalMessageId + '-' + #user?.id")
public Message getMessageByExternalId(String externalMessageId, User user) {
    if (!isServiceEnabled(user)) {
        return null;
    }

    FacebookClient client = helper.getFacebookClient(user);
    try {
        Post post = client.fetchObject(getFacebookId(externalMessageId), Post.class);
        return helper.postToMessage(post, user.getFacebookSettings()
                .isFetchImages(), user.getFacebookSettings().getUserId(), client);

    } catch (FacebookException ex) {
        handleException("Problem with getting a message from facebook", ex, user);
        return null;
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:19,代码来源:FacebookService.java

示例2: getMessagesOfUser

import com.restfb.exception.FacebookException; //导入依赖的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

示例3: getTopRecentMessages

import com.restfb.exception.FacebookException; //导入依赖的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

示例4: fetchFacebookUser

import com.restfb.exception.FacebookException; //导入依赖的package包/类
private AuthUser fetchFacebookUser(String accessToken)
{
    //TODO: this takes too long, maybe cache the access token for a configurable time
    FacebookClient client = new DefaultFacebookClient(accessToken, Version.VERSION_2_5);
    try
    {
        User user = client.fetchObject("me", User.class, Parameter.with("fields", "name,email"));
        if (user != null)
        {
            AuthUser authUser = new AuthUser();
            authUser.setName(user.getName());
            authUser.setEmail(user.getEmail());
            authUser.setAuthVendor(AuthVendor.FACEBOOK);
            authUser.setSession(accessToken);

            return authUser;
        }
    }
    catch (FacebookException ex)
    {
    }

    return null;
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:25,代码来源:FacebookAuthProvider.java

示例5: setGetStartedButton

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public void setGetStartedButton(CallToAction callToAction) throws FacebookException {
    requireNonNull(callToAction, "'callToAction' must not be null");
    List<CallToAction> callToActions = Arrays.asList(callToAction);
    facebookClient.publish(THREAD_SETTINGS_PATH, SendResponse.class,
            Parameter.with(SETTING_TYPE_PARAM_NAME, SettingTypeEnum.call_to_actions),
            Parameter.with(THREAD_STATE_PARAM_NAME, ThreadStateEnum.new_thread),
            Parameter.with(CALL_TO_ACTIONS_PARAM_NAME, callToActions));
}
 
开发者ID:marsbits,项目名称:restfbmessenger,代码行数:10,代码来源:DefaultMessenger.java

示例6: getUsersData

import com.restfb.exception.FacebookException; //导入依赖的package包/类
public Map<String, User> getUsersData(FacebookClient client, Set<String> userIds)
        throws FacebookException {
    if (userIds.isEmpty()) {
        return Collections.emptyMap();
    }

    String queryCriteria = Joiner.on(" or ").join(userIds);
    String query = USER_QUERY_FIELDS + queryCriteria + " LIMIT " + userIds.size();
    List<FqlUser> fbUsers = client.executeQuery(query, FqlUser.class);

    Map<String, User> users = new HashMap<String, User>(fbUsers.size());
    for (com.restfb.types.User fbUser : fbUsers) {
        User externalUser = new User();
        fillUserData(externalUser, fbUser);
        users.put(fbUser.getId(), externalUser);
    }

    return users;
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:20,代码来源:FacebookHelper.java

示例7: welshareToFacebookNames

import com.restfb.exception.FacebookException; //导入依赖的package包/类
private NameConversionResult welshareToFacebookNames(String text, FacebookClient client) throws FacebookException {
    List<String> usernames = WebUtils.extractMentionedUsernames(text);
    List<String> names = Lists.newArrayList();
    for (String username : usernames) {
        User wsUser = dao.getByUsername(username);
        if (wsUser != null && StringUtils.isNotEmpty(wsUser.getFacebookSettings().getUserId())) {
            com.restfb.types.User fbUser = client.fetchObject(wsUser
                    .getFacebookSettings().getUserId(),
                    com.restfb.types.User.class);
            String name = StringUtils.trimToEmpty(fbUser.getFirstName()) + " "
                        + StringUtils.trimToEmpty(fbUser.getLastName());
            names.add(name);
            text = text.replace("@" + username, name);
        }
    }
    NameConversionResult result = new NameConversionResult();
    result.setNames(names);
    result.setModifiedText(text);
    return result;
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:21,代码来源:FacebookService.java

示例8: like

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
@Async
public void like(String originalMessageId, ResharingDetails details, User user) {
    if (!isServiceEnabled(user)) {
        return;
    }
    FacebookClient client = helper.getFacebookClient(user);

    String fbId = getFacebookId(originalMessageId);

    try {
        client.publish("/" + fbId + "/likes", Boolean.class);

        // if it should not be reshared, but there's a comment, add it as reply
        if (!details.isShareAndLike()) {
            Message msg = new Message();
            msg.setText(details.getComment());
            msg.setAuthor(user);
            reply(originalMessageId, msg);
        }
    } catch (FacebookException e) {
        handleException("Problem with liking a message on facebook", e, user);
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:25,代码来源:FacebookService.java

示例9: storeSettings

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
@SqlTransactional
@EvictHomeStreamCacheStringParam
public User storeSettings(SocialNetworkSettings settings, String userId) {
    if (settings instanceof FacebookSettings) {
        User user = dao.getById(User.class, userId, true);
        FacebookSettings fbSettings = (FacebookSettings) settings;
        // fetch the facebook user id
        if (fbSettings.getUserId() == null) {
            FacebookClient client = helper.getFacebookClient(fbSettings);
            try {
                com.restfb.types.User current = client.fetchObject("me", com.restfb.types.User.class);
                fbSettings.setUserId(current.getId());
            } catch (FacebookException e) {
                handleException("Problem getting the id of the current user", e, user);
            }
        }
        user.setFacebookSettings(fbSettings);
        dao.persist(user);

        return user;
    }

    return null;
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:26,代码来源:FacebookService.java

示例10: getIncomingMessages

import com.restfb.exception.FacebookException; //导入依赖的package包/类
private List<Message> getIncomingMessages(long lastMessageMillis, User user) {
    if (!isServiceEnabled(user)) {
        return Collections.emptyList();
    }
    try {
        FacebookClient client = helper.getBackgroundFacebookClient(user);

        List<StreamPost> feed = client.executeFqlQuery(NEWS_FEED_QUERY + " AND created_time > "
                + (lastMessageMillis / DateTimeConstants.MILLIS_PER_SECOND + 1) + " LIMIT 20",
                StreamPost.class);

        List<Message> messages = helper.streamPostsToMessages(feed,
                user.getFacebookSettings().isFetchImages(),
                user.getFacebookSettings().getUserId(), client);

        return messages;
    } catch (FacebookException e) {
        //do nothing, will re-attempt on next run
        handleException("Problem retrieving incoming facebook messages", e, user);
        return Collections.emptyList();
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:23,代码来源:FacebookService.java

示例11: publishInitialMessage

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public void publishInitialMessage(User user) {
    if (!isServiceEnabled(user)) {
        return;
    }

    FacebookClient client = helper.getFacebookClient(user);
    try {
        //TODO i18nize
        client.publish(OWN_FEED,
                FacebookType.class,
                Parameter.with(MESSAGE_PARAM, "I am using Welshare!"),
                Parameter.with(LINK_PARAM, "http://welshare.com"));
    } catch (FacebookException e) {
        handleException("Problem sharing initial message to facebook", e, user);
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:18,代码来源:FacebookService.java

示例12: markNotificationsAsRead

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
@SqlTransactional
public void markNotificationsAsRead(User user) {
    if (!isServiceEnabled(user)) {
        return;
    }
    user = dao.getById(User.class, user.getId(), true);
    user.getFacebookSettings().setLastReadNotificationTimestamp(
            DateTimeUtils.currentTimeMillis());
    dao.persist(user);

    LegacyFacebookClient client = helper.getLegacyClient(user.getFacebookSettings().getToken());
    try {
        List<NotificationEvent> events = getUnreadNotifications(user);
        if (events.isEmpty()) {
            return;
        }
        List<String> ids = Lists.newArrayListWithCapacity(events.size());
        for (NotificationEvent event : events) {
            ids.add(((ExternalNotificationEvent) event).getExternalNotificationId());
        }
        client.execute("notifications.markRead", Parameter.with("notification_ids", ids));
    } catch (FacebookException ex) {
        handleException("Error marking messages as read", ex, user);
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:27,代码来源:FacebookService.java

示例13: getLikers

import com.restfb.exception.FacebookException; //导入依赖的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

示例14: getUserId

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public String getUserId(String username, User user) {
    if (!isServiceEnabled(user)) {
        return null;
    }

    FacebookClient client = helper.getFacebookClient(user);

    try {
        List<FqlUser> result = client.executeFqlQuery("SELECT uid FROM user WHERE uid='" + username + "' OR username='" + username + "'", FqlUser.class);
        if (result.isEmpty()) {
            return null;
        } else {
            return result.get(0).getId();
        }
    } catch (FacebookException ex) {
        handleException("Error finding user by username: " + username, ex, user);
        return null;
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:21,代码来源:FacebookService.java

示例15: getUserDetails

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public UserDetails getUserDetails(String externalUserId, User currentUser) {
    if (!isServiceEnabled(currentUser)) {
        return null;
    }

    FacebookClient client = helper.getFacebookClient(currentUser);

    try {
        com.restfb.types.User fbUser = client.fetchObject(getFacebookId(externalUserId), com.restfb.types.User.class);
        if (fbUser == null) {
            throw new FacebookGraphException("0", "null facebook user returned", 500);
        }
        User user = new User();
        helper.fillUserData(user, fbUser);
        UserDetails details = new UserDetails(user);
        FqlUser result = client.executeFqlQuery("SELECT friend_count FROM user WHERE uid=me()", FqlUser.class).get(0);
        details.setFollowers(result.getFriendCount());
        return details;
    } catch (FacebookException ex) {
        handleException("Problem getting facebook user", ex, currentUser);
        return null;
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:25,代码来源:FacebookService.java


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