Twitter4J sendDirectMessage returns 页面不存在

Twitter4J sendDirectMessage returns page does not exist

我想开发一个可以发送直接消息的应用程序看这个:

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:!");
}

这是 return 错误:

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 应用程序上的读取、写入和直接消息权限。

抱歉我的英语不好。

您使用的是哪个版本的 Twitter4J?新的直接消息 API 才推出几周,因此您可能需要一个新版本。

适用于此版本,将其添加到 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>

祝你好运。

Twitter 的直接消息功能使用 Twitter4j-core-4.0.7 版本。 其他版本的 Twitter4j 库显示 TwitterException of User Not Found or Page Does does not exist.