• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FacebookException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: reshare

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public void reshare(String originalMessageId, String comment, User user) {

    if (!isServiceEnabled(user)) {
        return;
    }
    FacebookClient client = helper.getFacebookClient(user);

    String fbId = getFacebookId(originalMessageId);

    try {
        Post post = client.fetchObject(fbId, Post.class);
        Message message = helper.postToMessage(post, false, null, client);
        message.setAuthor(user);
        String commentPrefix = "";
        if (StringUtils.isNotBlank(comment)) {
            commentPrefix = comment + ": ";
        }
        message.setText(commentPrefix + message.getShortText() + " (via " + post.getFrom().getName() + ")");
        share(message, user);
    } catch (FacebookException ex) {
        handleException("Failed to reshare a message on FB", ex, user);
    }
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:25,代码来源:FacebookService.java


示例17: getExtendedAccessToken

import com.restfb.exception.FacebookException; //导入依赖的package包/类
/**
 * Exchange the short lived token (2h) for a long lived one (60j).
 * 
 * @param accessToken Short lived token
 * @return Long lived token
 * @throws AuthenticationException Invalid token
 */
public String getExtendedAccessToken(String accessToken) throws AuthenticationException {
    FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
    AccessToken extendedAccessToken = null;
    try {
        extendedAccessToken = facebookClient.obtainExtendedAccessToken(facebookAppId, facebookAppSecret, accessToken);

        if (log.isDebugEnabled()) {
            log.debug(MessageFormat.format("Got long lived session token {0} for token {1}", extendedAccessToken, accessToken));
        }
    } catch (FacebookException e) {
        if (e.getMessage().contains("Error validating access token")) {
            throw new AuthenticationException("Error validating access token");
        }
            
        throw new RuntimeException("Error exchanging short lived token for long lived token", e);
    }
    return extendedAccessToken.getAccessToken();
}
 
开发者ID:sismics,项目名称:books,代码行数:26,代码来源:FacebookService.java


示例18: fetchObject

import com.restfb.exception.FacebookException; //导入依赖的package包/类
public static <T> T fetchObject(FacebookClient fbClient, String name, Class<T> objClass,
    Parameter... parameters) {
  try {
    return fbClient.fetchObject(name, objClass, parameters);
  } catch(FacebookException e) {
    if (e instanceof FacebookOAuthException) {
      throw ErrorResponseMsg.createException(e.getMessage(), ErrorInfo.Type.AUTHENTICATION);
    }
    if (e.getMessage().toLowerCase().contains("unsupported get request")) {
      // This seems to be thrown when there is a permissions issue.
      // http://stackoverflow.com/questions/6843796/graph-api-returns-false-or-unsupported-get-request-accessing-public-facebook
      throw ErrorResponseMsg.createException(
        "Access to faceboook object '" + name + "' is restricted",
        ErrorInfo.Type.PARTNER_SERVICE_FAILURE);
    }
    throw ErrorResponseMsg.createException(e, ErrorInfo.Type.PARTNER_SERVICE_FAILURE);
  }
}
 
开发者ID:karma-exchange-org,项目名称:karma-exchange,代码行数:19,代码来源:FacebookSocialNetworkProvider.java


示例19: notify

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
protected void notify(Parameters parameters) throws NotificationException {
    try {
        FacebookClient facebookClient =
                createFacebookClient(getConfiguration().getString(KEY_ACCESS_TOKEN));

        FacebookType publishResponse;

        if (hasMovie()) {
            publishResponse = facebookClient.publish("me/videos", FacebookType.class,
                    BinaryAttachment.with(movie.getFileName().toString(),
                            Files.readAllBytes(movie),
                            Files.probeContentType(movie)),
                    com.restfb.Parameter.with("description", message));
        } else if (hasPhoto()) {
            publishResponse = facebookClient.publish("me/photos", FacebookType.class,
                    BinaryAttachment.with(
                            photo.getFileName().toString(),
                            Files.readAllBytes(photo),
                            Files.probeContentType(photo)),
                    com.restfb.Parameter.with("message", message));
        } else {
            publishResponse =
                    facebookClient.publish("me/feed", FacebookType.class,
                            com.restfb.Parameter.with("message", message));
        }

        log.debug("Published content has ID {}", publishResponse.getId());
    } catch (FacebookException | IOException e) {
        throw new NotificationException(e);
    }
}
 
开发者ID:yfiton,项目名称:yfiton,代码行数:33,代码来源:FacebookNotifier.java


示例20: textMessage

import com.restfb.exception.FacebookException; //导入依赖的package包/类
@Override
public SendResponse textMessage(MessagingType type, MessageRecipient recipient, String text, NotificationTypeEnum notificationType,
        MessageTag tag)
        throws FacebookException {
    requireNonNull(recipient, "'recipient' must not be null");
    requireNonNull(text, "'text' must not be null");
    Message message = new Message(text);
    return message(type, recipient, message, notificationType, tag);
}
 
开发者ID:marsbits,项目名称:restfbmessenger,代码行数:10,代码来源:DefaultSendOperations.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PGPException类代码示例发布时间:2022-05-22
下一篇:
Java TextFieldWithHistoryWithBrowseButton类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap