本文整理了Java中twitter4j.Twitter.sendDirectMessage()
方法的一些代码示例,展示了Twitter.sendDirectMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Twitter.sendDirectMessage()
方法的具体详情如下:
包路径:twitter4j.Twitter
类名称:Twitter
方法名:sendDirectMessage
[英]Sends a new direct message to the specified user from the authenticating user. Requires both the user and text parameters below. The text will be trimed if the length of the text is exceeding 140 characters.
This method calls http://twitter.com/direct_messages/new
[中]从身份验证用户向指定用户发送新的直接消息。需要下面的用户和文本参数。如果文本长度超过140个字符,文本将被修剪。
此方法调用http://twitter.com/direct_messages/new
代码示例来源:origin: net.homeip.yusuke/twitter4j
public DirectMessage sendDirectMessage(String text) throws TwitterException {
return twitter.sendDirectMessage(this.getName(), text);
}
代码示例来源:origin: jchampemont/WTFDYUM
@Override
public void sendDirectMessage(final Principal principal, final Long toUserId, final String text)
throws WTFDYUMException {
try {
twitter(principal).sendDirectMessage(toUserId, text);
} catch (final TwitterException e) {
log.debug("Error while sendDirectMessage", e);
throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR);
}
}
代码示例来源:origin: org.twitter4j/twitter4j-async
@Override
public void invoke(List<TwitterListener> listeners) throws TwitterException {
DirectMessage directMessage = twitter.sendDirectMessage(userId, text);
for (TwitterListener listener : listeners) {
try {
listener.sentDirectMessage(directMessage);
} catch (Exception e) {
logger.warn("Exception at sendDirectMessage", e);
}
}
}
});
代码示例来源:origin: org.twitter4j/twitter4j-async
@Override
public void invoke(List<TwitterListener> listeners) throws TwitterException {
DirectMessage directMessage = twitter.sendDirectMessage(screenName, text);
for (TwitterListener listener : listeners) {
try {
listener.sentDirectMessage(directMessage);
} catch (Exception e) {
logger.warn("Exception at sendDirectMessage", e);
}
}
}
});
代码示例来源:origin: net.homeip.yusuke/twitter4j
/**
* Usage: java twitter4j.examples.DirectMessage senderID senderPassword message recipientId
* @param args String[]
*/
public static void main(String[] args) {
if (args.length < 4) {
System.out.println("No TwitterID/Password specified.");
System.out.println("Usage: java twitter4j.examples.DirectMessage senderID senderPassword message recipientId");
System.exit( -1);
}
Twitter twitter = new Twitter(args[0], args[1]);
try {
DirectMessage message = twitter.sendDirectMessage(args[2], args[3]);
System.out.println("Direct message successfully sent to " +
message.getRecipientScreenName());
System.exit(0);
} catch (TwitterException te) {
System.out.println("Failed to send message: " + te.getMessage());
System.exit( -1);
}
}
}
代码示例来源:origin: org.apache.camel/camel-twitter
public void process(Exchange exchange) throws Exception {
// send direct message
String toUsername = user;
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(TwitterConstants.TWITTER_USER, String.class))) {
toUsername = exchange.getIn().getHeader(TwitterConstants.TWITTER_USER, String.class);
}
String text = exchange.getIn().getBody(String.class);
if (toUsername.isEmpty()) {
throw new CamelExchangeException("Username not configured on TwitterEndpoint", exchange);
} else {
log.debug("Sending to: {} message: {}", toUsername, text);
User userStatus = endpoint.getProperties().getTwitter().showUser(toUsername);
endpoint.getProperties().getTwitter().sendDirectMessage(userStatus.getId(), text);
}
}
代码示例来源:origin: org.mule.modules/mule-module-twitter
/**
* Sends a new direct message to the specified user from the authenticating user.
* Requires both the user and text parameters below. The text will be trimmed if
* the length of the text is exceeding 140 characters.
* <p/>
* {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:sendDirectMessageByUserId}
*
* @param userId The user ID of the user to whom send the direct message
* @param message The text of your direct message
* @return the {@link DirectMessage}
* @throws TwitterException when Twitter service or network is unavailable
*/
@Processor
public DirectMessage sendDirectMessageByUserId(long userId, String message) throws TwitterException {
return getConnectionManagement().getTwitterClient().sendDirectMessage(userId, message);
}
代码示例来源:origin: org.mule.modules/mule-module-twitter
/**
* Sends a new direct message to the specified user from the authenticating user.
* Requires both the user and text parameters below. The text will be trimmed if
* the length of the text is exceeding 140 characters.
* <p/>
* {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:sendDirectMessageByScreenName}
*
* @param screenName The screen name of the user to whom send the direct message
* @param message The text of your direct message
* @return the {@link DirectMessage}
* @throws TwitterException when Twitter service or network is unavailable
*/
@Processor
public DirectMessage sendDirectMessageByScreenName(String screenName, String message) throws TwitterException {
return getConnectionManagement().getTwitterClient().sendDirectMessage(screenName, message);
}
代码示例来源:origin: OpenNMS/opennms
/** {@inheritDoc} */
@Override
public int send(List<Argument> arguments) {
Twitter svc = buildUblogService(arguments);
String destUser = findDestName(arguments);
DirectMessage response;
if (destUser == null || "".equals(destUser)) {
LOG.error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead.");
return 1;
}
// In case the user tried to be helpful, avoid a double @@
if (destUser.startsWith("@"))
destUser = destUser.substring(1);
String fullMessage = buildMessageBody(arguments);
LOG.debug("Dispatching microblog DM notification at base URL '{}' with destination user '{}' and message '{}'", svc.getConfiguration().getClientURL(), destUser, fullMessage);
try {
response = svc.sendDirectMessage(destUser, fullMessage);
} catch (TwitterException e) {
LOG.error("Microblog notification failed at service URL '{}' to destination user '{}'", svc.getConfiguration().getClientURL(), destUser, e);
return 1;
}
LOG.info("Microblog DM notification succeeded: DM sent with ID {}", response.getId());
return 0;
}
}
代码示例来源:origin: Tristan971/Lyrebird
public CompletableFuture<DirectMessage> sendMessage(final User recipient, final String content) {
LOG.debug("Sending direct message to [{}] with content {}", recipient.getScreenName(), content);
return CompletableFuture.supplyAsync(() -> sessionManager.doWithCurrentTwitter(
twitter -> twitter.sendDirectMessage(recipient.getId(), content))
).thenApplyAsync(
msgReq -> msgReq.onSuccess(dme -> {
LOG.debug("Sent direct message! {}", dme);
directMessages.addDirectMessage(dme);
}).onFailure(
err -> LOG.error("Could not send direct message!", err)
).getOrElseThrow((Function<Throwable, RuntimeException>) RuntimeException::new)
).whenCompleteAsync((res, err) -> {
if (err != null) {
LOG.error("Could not correctly executed the direct message sending request!", err);
}
});
}
代码示例来源:origin: org.jbpm.contrib/twitter-workitem
@Before
public void setUp() {
try {
when(auth.getTwitterService(anyString(),
anyString(),
anyString(),
anyString(),
any(boolean.class))).thenReturn(twitter);
when(twitter.updateStatus(any(StatusUpdate.class))).thenReturn(status);
when(twitter.sendDirectMessage(anyString(),
anyString())).thenReturn(directMessage);
} catch (Exception e) {
fail(e.getMessage());
}
}
代码示例来源:origin: org.jbpm.contrib/twitter-workitem
public void executeWorkItem(WorkItem workItem,
WorkItemManager workItemManager) {
String message = (String) workItem.getParameter("Message");
String screenName = (String) workItem.getParameter("ScreenName");
// debug is optional (default to false)
boolean debugOption = false;
if (workItem.getParameter("DebugEnabled") != null) {
debugOption = Boolean.parseBoolean((String) workItem.getParameter("DebugEnabled"));
}
try {
RequiredParameterValidator.validate(this.getClass(),
workItem);
Twitter twitter = auth.getTwitterService(this.consumerKey,
this.consumerSecret,
this.accessKey,
this.accessSecret,
debugOption);
directMessage = twitter.sendDirectMessage(screenName,
message);
workItemManager.completeWorkItem(workItem.getId(),
null);
} catch (Exception e) {
handleException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!