Страница возврата Twitter4J sendDirectMessage не существует - PullRequest
0 голосов
/ 02 ноября 2018

Я хочу разработать приложение, которое может отправлять прямые сообщения, смотрите это:

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.

извините за мой плохой английский.

Ответы [ 3 ]

0 голосов
/ 03 ноября 2018

Это работа с этой версией, добавьте ее в 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>

Удачи.

0 голосов
/ 28 января 2019

Используйте версию Twitter4j-core-4.0.7 для функции прямого сообщения Twitter. Другая версия библиотеки Twitter4j показывает исключение TwitterException для пользователя не найден или страница не существует.

0 голосов
/ 02 ноября 2018

Какую версию Twitter4J вы используете? Новому API Direct Message всего несколько недель, поэтому вам может понадобиться новая версия.

...