java - Twitter4J sendDirectMessage 返回页面不存在

标签 java api twitter twitter4j

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

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

抱歉我的英语不好。

最佳答案

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

祝你好运。

关于java - Twitter4J sendDirectMessage 返回页面不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53119677/

相关文章:

javascript - React 中嵌套获取请求的问题

java - 在Java中搜索和编辑ArrayList中的元素

java - Observable 模式的替代方案?

facebook - 使用Facebook API获取用户组列表

php - Paypal REST-API 预批准支付场景

objective-c - 如何创建类似于 Twitter iPhone 应用程序中“我”选项卡下的第一部分的自定义 UITableViewCell

python - Twitter 主题标签搜索结果 - 超过 7 天

java - Java 中与 Stack 相关的几个问题

Java - 如何获取变量形式 JTeXtField 并在算法 J48 中使用

android - twitter 没有重定向到 android 应用程序中的回调 url