Android How to send DirectMessage using Twitter4j lib?

634 views Asked by At

I'm using Twitter4j lib. I'm unable to send direct message to my followers.

new Thread(new Runnable() {

@Override
        public void run() {
            // TODO Auto-generated method stub
            DirectMessage message = null;
            try {

                message = twitter.sendDirectMessage(friendId, messsage);
                Log.d(" *** Twiiter Sent message **** ", "Sent Message is : "
                        + message.getText() + " \t Sender name: "
                        + message.getRecipientScreenName());
            } catch (TwitterException e) {
                e.printStackTrace();
            }

        }
    }).start();

I'm getting following exception:

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

Relevant discussions can be found on the Internet at:

11-13 16:46:55.481: W/System.err(1990): http://www.google.co.jp/search?q=9bf58966 or 11-13 16:46:55.481: W/System.err(1990): http://www.google.co.jp/search?q=17d1fbfd 11-13 16:46:55.481: W/System.err(1990): TwitterException{exceptionCode=[9bf58966-17d1fbfd], statusCode=404, message=Sorry, that page does not exist, code=34, retryAfter=-1, rateLimitStatus=null, version=4.0.1} 11-13 16:46:55.481: W/System.err(1990): at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164) 11-13 16:46:55.481: W/System.err(1990): at twitter4j.HttpClientBase.request(HttpClientBase.java:53) 11-13 16:46:55.481: W/System.err(1990): at twitter4j.HttpClientBase.post(HttpClientBase.java:82) 11-13 16:46:55.481: W/System.err(1990): at twitter4j.TwitterImpl.post(TwitterImpl.java:2004) 11-13 16:46:55.481: W/System.err(1990): at twitter4j.TwitterImpl.sendDirectMessage(TwitterImpl.java:368) 11-13 16:46:55.481: W/System.err(1990): at com.dman.tweetfragment.Fragments.MainFragment$6.run(MainFragment.java:993) 11-13 16:46:55.481: W/System.err(1990): at java.lang.Thread.run(Thread.java:856) 11-13 16:46:55.481: W/dalvikvm(1990): threadid=24: thread exiting with uncaught exception (group=0xa6296288)

Please provide your valuable suggestions here. Thank you.

2

There are 2 answers

0
ashe On

Check your friendId. It must be Long. If it String then user's screenName must be used.

0
Praveen Kumar Sugumaran On

Thank you All. I found answer. We have to pass twitter user screenName instead of screenId. screenId not works for me. I tried with screenName. It works fine.

 message = twitter.sendDirectMessage(friendscreenName, messsage);