Twitter exception4 04:The URI requested is invalid

☆樱花仙子☆ 提交于 2019-12-24 06:03:42

问题


I want to send direct message to user's followers using my android application.I have tried following code

      String access_token = mSharedPreferences.getString(
                        Constants.PREF_KEY_OAUTH_TOKEN, "");
                // Access Token Secret
                String access_token_secret = mSharedPreferences.getString(
                        Constants.PREF_KEY_OAUTH_SECRET, "");

                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setDebugEnabled(true);
                builder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
                builder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
                builder.setOAuthAccessToken(access_token);
                builder.setOAuthAccessTokenSecret(access_token_secret);


                TwitterFactory tf = new TwitterFactory(builder.build());
                Twitter twitter = tf.getInstance();


                DirectMessage message = null;
                try {
                    message = twitter.sendDirectMessage(
                            frndsDetails.get(position).getId(), "Hi");
                    System.out.println("Sent: " + message.getText()
                            + " to @" + message.getRecipientScreenName());

                } catch (TwitterException e) {
                    // TODO Auto-generated catch block
                    Log.e("Twitter exception", "" + e.getMessage());
                    e.printStackTrace();
                }

But got following exception

02-26 13:48:16.287: E/Twitter exception(707): 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. 02-26 13:48:16.287: E/Twitter exception(707): message - Sorry, that page does not exist 02-26 13:48:16.287: E/Twitter exception(707): code - 34 02-26 13:48:16.397: W/System.err(707): at android.view.View.performClick(View.java:3511)

Is there any other method for sending direct message.Please help me. Thanks in advance.


回答1:


I have used following code in my application for sending direct messages to the followers. May be this can helpful to you.

StringBuilder builder = new StringBuilder();
builder.append("@").append(twitterFriendObj.screenName).append(" ");
Status status = twitter.updateStatus(builder+"Hi this is test message");

Here we need to send follower screen name to send direct message.



来源:https://stackoverflow.com/questions/15084509/twitter-exception4-04the-uri-requested-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!