如何通过Android应用程序将URL与url发送到Twitter帐户?

时间:2012-11-27 11:42:03

标签: android twitter message

我需要通过应用程序向用户的Twitter好友发送带有URL链接的直接消息。使用我当前的代码无法成功发送消息:

 public void sendTwitterfriends()
 {
     HttpClient httpClient = new DefaultHttpClient();
     HttpPost request = new HttpPost("https://api.twitter.com/1/direct_messages/new.format");
     List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                    postParameters.add(new BasicNameValuePair("user_id", "friendsuserid"));
      postParameters.add(new BasicNameValuePair("text", "Hi Testing"));
      try {
          UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters);
          request.setEntity(entity);       
          HttpResponse response= httpClient.execute(request);
      }catch (Exception e) {
                // TODO: handle exception
      }
}

由于

0 个答案:

没有答案