嗨,我现在从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();
}
答案 0 :(得分:1)
您知道特定用户的用户名吗?如果是的话,
然后这样做:
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);
}
});
}
我不知道它是否有效。但通常Twitter中特定用户的推文格式相同。