0

嗨,我正在从 twitter 获取朋友列表,现在我想向从列表中选择的特定用户发送推文。任何代码片段将不胜感激。这是我要NullPointerException上车了twitter.sendmessage("id of user","msg")

private void tweet(){
    setTitle("Tweet");
    AlertDialog.Builder inputDialog;
    inputDialog = new AlertDialog.Builder(MainActivity.this);
    inputDialog.setTitle("Enter Tweet");
    et_input = new EditText(MainActivity.this);
    et_input.setWidth(250);
    et_input.setHeight(30);
    inputDialog.setView(et_input);
    inputDialog.setPositiveButton("Ok",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        txt_tweet= et_input.getText().toString();
        System.out.println("String what i have type "+txt_tweet);
            try{
               twitter.sendMessage("testsynapse1", txt_tweet);
                Toast.makeText(MainActivity.this,
                    "Tweet Successful", Toast.LENGTH_LONG).show();
            }
            catch (TwitterException e) {
                // TODO: handle exception
                e.getMessage();
            }
        }
    });
    inputDialog.setNegativeButton("Cancle",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        }
    });
    inputDialog.show();
}
4

1 回答 1

1

Do you know the username of particular user? If yes,

Then do like this:

String tweetToPost="@"+userName+"%20"+"your message"; 

postTweet(tweetToPost); 


public void postTweet(String str){
  String url="https://twitter.com/intent/tweet?text="+str.replace(" ","%20");

  WebView wv=new WebView(this);
        wv.loadUrl(url);
        setContentView(wv);
        wv.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
            }


        });


}

I don't know if it works or not. But generally tweets to a specific user in Twitter are in the same format.

于 2012-09-05T10:49:51.723 回答