Search code examples
javaapitwittertwitter4j

Twitter4J sendDirectMessage returns page does not exist


I want to develop an application who can send direct messages look this:

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());
    }
}

I call to this statement with:

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

it's return error:

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

Note:

The functions search(), getHomeTimeline() and updateStatus() works.

I have activated Read, Write and Direct messages on twitter application permissions.

sorry for my bad english.


Solution

  • Which version of Twitter4J are you using? The new Direct Message API is only a few weeks old so you may need a new version.