twitter4j.Twitter.getDirectMessages()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中twitter4j.Twitter.getDirectMessages()方法的一些代码示例,展示了Twitter.getDirectMessages()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Twitter.getDirectMessages()方法的具体详情如下:
包路径:twitter4j.Twitter
类名称:Twitter
方法名:getDirectMessages

Twitter.getDirectMessages介绍

[英]Returns a list of the direct messages sent to the authenticating user.
This method calls http://twitter.com/direct_messages
[中]返回发送给身份验证用户的直接消息列表。
此方法调用http://twitter.com/direct_messages

代码示例

代码示例来源:origin: net.homeip.yusuke/twitter4j

/**
 * Returns a list of the direct messages sent to the authenticating user.
 * <br>This method calls http://twitter.com/direct_messages
 *
 * @param page the number of page
 * @return List
 * @throws TwitterException when Twitter service or network is unavailable
 * @deprecated Use getDirectMessages(Paging paging) instead
 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct_messages">Twitter API Wiki / Twitter REST API Method: direct_messages</a>
 */
public List<DirectMessage> getDirectMessagesByPage(int page) throws TwitterException {
  return getDirectMessages(new Paging(page));
}

代码示例来源:origin: net.homeip.yusuke/twitter4j

/**
 * Returns a list of the direct messages sent to the authenticating user.
 * <br>This method calls http://twitter.com/direct_messages
 *
 * @param sinceId Returns only direct messages with an ID greater than (that is, more recent than) the specified ID.
 * @return list of direct messages
 * @throws TwitterException when Twitter service or network is unavailable
 * @deprecated Use getDirectMessages(Paging paging) instead
 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct_messages">Twitter API Wiki / Twitter REST API Method: direct_messages</a>
 */
public List<DirectMessage> getDirectMessages(int sinceId) throws TwitterException {
  return getDirectMessages(new Paging((long)sinceId));
}

代码示例来源:origin: org.apache.camel/camel-twitter

@Override
  public List<Exchange> directConsume() throws TwitterException {
    return TwitterEventType.DIRECT_MESSAGE.createExchangeList(
      endpoint,
      getTwitter().getDirectMessages()
    );
  }
}

代码示例来源:origin: org.twitter4j/twitter4j-async

@Override
  public void invoke(List<TwitterListener> listeners) throws TwitterException {
    ResponseList<DirectMessage> directMessages = twitter.getDirectMessages();
    for (TwitterListener listener : listeners) {
      try {
        listener.gotDirectMessages(directMessages);
      } catch (Exception e) {
        logger.warn("Exception at getDirectMessages", e);
      }
    }
  }
});

代码示例来源:origin: org.twitter4j/twitter4j-async

@Override
  public void invoke(List<TwitterListener> listeners) throws TwitterException {
    ResponseList<DirectMessage> directMessages = twitter.getDirectMessages(paging);
    for (TwitterListener listener : listeners) {
      try {
        listener.gotDirectMessages(directMessages);
      } catch (Exception e) {
        logger.warn("Exception at getDirectMessages", e);
      }
    }
  }
});

代码示例来源:origin: net.homeip.yusuke/twitter4j

/**
   * Usage: java twitter4j.examples.GetDirectMessages ID Password
   * @param args String[]
   */
  public static void main(String[] args) {
    if (args.length < 2) {
      System.out.println("No TwitterID/Password specified.");
      System.out.println(
        "Usage: java twitter4j.examples.GetDirectMessages ID Password");
      System.exit( -1);
    }
    Twitter twitter = new Twitter(args[0], args[1]);
    try {
      List<DirectMessage> messages = twitter.getDirectMessages();
      for (DirectMessage message : messages) {
        System.out.println("Sender:" + message.getSenderScreenName());
        System.out.println("Text:" + message.getText() + "\n");
      }
      System.exit(0);
    } catch (TwitterException te) {
      System.out.println("Failed to get messages: " + te.getMessage());
      System.exit( -1);
    }
  }
}

代码示例来源:origin: net.homeip.yusuke/twitter4j

/**
 * Returns a list of the direct messages sent to the authenticating user.
 * <br>This method calls http://twitter.com/direct_messages
 *
 * @param page    the number of page
 * @param sinceId Returns only direct messages with an ID greater than (that is, more recent than) the specified ID.
 * @return List
 * @throws TwitterException when Twitter service or network is unavailable
 * @since Twitter4J 2.0.0
 * @deprecated Use getDirectMessages(Paging paging) instead
 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct_messages">Twitter API Wiki / Twitter REST API Method: direct_messages</a>
 */
public List<DirectMessage> getDirectMessages(int page
    , int sinceId) throws TwitterException {
  return getDirectMessages(new Paging(page).sinceId(sinceId));
}

代码示例来源:origin: Tristan971/Lyrebird

@Override
public void refresh() {
  if (!sessionManager.isLoggedInProperty().getValue()) {
    LOG.debug("Logged out, not refreshing direct messages.");
    return;
  }
  CompletableFuture.runAsync(() -> {
    LOG.debug("Requesting last direct messages.");
    sessionManager.getCurrentTwitter()
           .mapTry(twitter -> twitter.getDirectMessages(20))
           .onSuccess(this::addDirectMessages)
           .onFailure(err -> LOG.error("Could not load direct messages successfully!", err));
  });
}

代码示例来源:origin: org.apache.camel/camel-twitter

@Override
public List<Exchange> pollConsume() throws TwitterException {
  List<DirectMessage> directMessages =  getTwitter().getDirectMessages(getLastIdPaging());
  for (int i = 0; i < directMessages.size(); i++) {
    setLastIdIfGreater(directMessages.get(i).getId());
  }
  return TwitterEventType.DIRECT_MESSAGE.createExchangeList(endpoint, directMessages);
}

相关文章