2

我必须通过 Twitter4j API 向用户 Twitter 帐户发送直接消息。

 try {
                    String token =  mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
                    String secret =  mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");
                  Twitter twitter = new TwitterFactory().getInstance();
                        ConfigurationBuilder cb = new ConfigurationBuilder();
                        cb.setDebugEnabled(true)
                                .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
                                .setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
                                .setOAuthAccessToken(token)
                                .setOAuthAccessTokenSecret(secret);
                        TwitterFactory tf = new TwitterFactory(cb.build());
                        twitter = tf.getInstance();
                        twitter.sendDirectMessage("Friendtwitterid", "Hi testing");
                    } catch (TwitterException te) 
                    {
                        te.printStackTrace();
                    }

但输出将是:

Failed to send a direct message: 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.

请帮忙。

4

0 回答 0