android - Posted tweet doesn't show on Twitter timeline -
i using edit text box , post button post tweets on twitter's timeline using app.
but after processing "status updated successfully" toast appears, tweet not showing on timeline... gives error 400 in logcat , shows message bad authentication data!! new oauth. how can fix problem?
here code:
public class postcommentactivity extends activity { private static final string consumer_key = "*****"; private static final string consumer_secret = "*******"; static string preference_name = "twitter_oauth"; static final string pref_key_oauth_token = "oauth_token"; static final string pref_key_oauth_secret = "oauth_token_secret"; static final string pref_key_twitter_login = "istwitterlogedin"; sharedpreferences msharedpreferences; progressdialog pdialog; edittext et; button postbtn; twitter twitter; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub setcontentview(r.layout.post_comment); super.oncreate(savedinstancestate); et = (edittext) findviewbyid(r.id.edittext); msharedpreferences = getapplicationcontext().getsharedpreferences("mypref", 0); postbtn = (button) findviewbyid(r.id.post_btn); postbtn.setonclicklistener(new onclicklistener() {@override public void onclick(view v) { // status edittext twitter twitter = twitterfactory.getsingleton(); string status = et.gettext().tostring(); // check blank text if (status.trim().length() > 0) { // update status new updatetwitterstatus().execute(status); } else { // edittext empty toast.maketext(getapplicationcontext(), "please enter status message", toast.length_short).show(); } } }); } class updatetwitterstatus extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(postcommentactivity.this); pdialog.setmessage("updating twitter..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } /** * getting places json * **/ protected string doinbackground(string... args) { log.d("tweet text", "> " + args[0]); string status = args[0]; try { configurationbuilder builder = new configurationbuilder(); builder.setoauthconsumerkey(consumer_key); builder.setoauthconsumersecret(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); twitter.setoauthaccesstoken(accesstoken); // update status twitter4j.status response = twitter.updatestatus(status); log.d("status", "> " + response.gettext()); } catch (twitterexception e) { // error in updating status log.d("twitter update error", e.getmessage()); } return null; } protected void onpostexecute(string file_url) { // dismiss dialog after getting products pdialog.dismiss(); // updating ui background thread runonuithread(new runnable() { @override public void run() { toast.maketext(getapplicationcontext(), "status tweeted successfully", toast.length_short).show(); // clearing edittext field et.settext(""); } }); }} }
i got solution... try code:
public class postcommentactivity extends activity { private static final string consumer_key = "***"; private static final string consumer_secret = "******"; sharedpreferences msharedpreferences; edittext et; button postbtn; requesttoken requesttoken; twitter twitter; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub setcontentview(r.layout.post_comment); super.oncreate(savedinstancestate); if (android.os.build.version.sdk_int > 9) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder() .permitall().build(); strictmode.setthreadpolicy(policy); } et = (edittext) findviewbyid(r.id.edittext); msharedpreferences = getapplicationcontext().getsharedpreferences("mypref", 0); postbtn = (button) findviewbyid(r.id.post_btn); postbtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string token = "*****"; string secret = "*****"; accesstoken = new accesstoken(token, secret); twitter twitter = new twitterfactory().getinstance(); twitter.setoauthconsumer(consumer_key, consumer_secret); twitter.setoauthaccesstoken(a); string status = et.gettext().tostring(); if ((status.trim().length() > 0)) { try { twitter.updatestatus(status); toast.maketext(getapplicationcontext(), "status tweeted successfully", toast.length_short).show(); // clearing edittext field et.settext(""); } catch (twitterexception e) { e.printstacktrace(); } } else { // edittext empty toast.maketext(getapplicationcontext(), "please enter status message", toast.length_short).show(); } } }); } }
Comments
Post a Comment