Twitter4J sendDirectMessage返回页面不存在



我想开发一个可以直接发送消息的应用程序,如下所示:

public static void sendDirectMessage(Long recipientId, String message){
System.out.print("[Bot] Sending message to @"+recipientId+"...  ");
try {
twitter.sendDirectMessage(recipientId, message);
System.out.println("done");
} catch (TwitterException e) {
System.out.println("fail");
e.printStackTrace();
System.err.println("[Error] "+e.getErrorMessage());
}
}

我呼吁这份声明:

private static String
customer_key = "",
Oth_key = "",
access_token = "",
access_key = "";
private static TwitterBot bot;
public static void main(String[] args) {
try {
bot = new TwitterBot(customer_key, Oth_key, access_token, access_key);
} catch (TwitterException e) {
e.printStackTrace();
} catch (InterruptedException e) {
System.err.println("[Err] "+e.getMessage());
}
bot.sendDirectMessage(bot.getUserData("AbA2L1").getId(), "Message test:!");
}

返回错误:

404:The URI requested is invalid or the resource requested, such as a user, does not exists. Also returned when the requested format is not supported by the requested method.
message - Sorry, that page does not exist.
code - 34

注:

函数search((、getHomeTimeline((和updateStatus((起作用。

我已经激活了twitter应用程序权限上的读、写和直接消息。

抱歉我英语不好。

可以使用此vertion,将其添加到pom.xml文件中:

<dependencies>
<!-- https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core -->
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.7</version>
</dependency>
</dependencies>

祝你好运。

您正在使用哪个版本的Twitter4J?新的直接消息API只有几周的历史,因此您可能需要一个新版本。

使用Twitter4j-core-4.0.7版本实现Twitter的直接消息功能。其他版本的Twitter4j库显示用户未找到或页面不存在的TwitterException。

最新更新