我想在twitter上发布我的消息。当我点击按钮时,它会向我显示您的数据已在Twitter上发布的消息,但是当我检查时我没有收到任何消息。这是我的代码。
btnUpdateStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Call update status function
// Get the status from EditText
String status = txtUpdate.getText().toString();
new updateTwitterStatus().execute(status);
}
});
这里是更新twitterstatus类
private class updateTwitterStatus extends AsyncTask<String,Void,Void>
{
@Override
protected void onPreExecute()
{
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Updating to twitter...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(String... screen_name)
{
String status = null;
try {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
// Access Token
String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
// Access Token Secret
String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");
AccessToken accessToken = new AccessToken(access_token, access_token_secret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
// Update status
twitter4j.Status response = twitter.updateStatus(status);
Log.i(""+response, "value");
Log.d("Status", "> " + response.getText());
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
e.printStackTrace();
}
return null;
}
/// }
@Override
protected void onPostExecute(Void result)
{
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Status tweeted successfully", Toast.LENGTH_SHORT)
.show();
// Clearing EditText field
txtUpdate.setText("");
}
});
}
}
请帮帮我。我发现这几天,我知道我已经问了这个,但我没有得到任何合适的解决方案,谢谢你。
答案 0 :(得分:0)
对于twitter,有两个库。
您可以选择SocialAuth library(管理良好且易于使用)