• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Projects
    • GStaticMap WP Plugin
  • Contact
  • Privacy Policy

Lorenz Blog

All About Web & Mobile Application Development

  • Featured Articles
  • Gadgets
    • Android
    • Blackberry
  • Programming
    • Android
    • PHP
    • Java Script
    • MySQL
    • Postgresql
    • Flex
    • Web
  • Software
    • Mac OS
    • Windows
    • Linux
  • Web
You are Here » Home >> Information Technology >> Programming >> Android >> How to Post Twitter Status from Android

How to Post Twitter Status from Android

February 26, 2011 by Lorensius Londa 289 Comments

While developing one of my Android application, i found it was hard to find a good and simple tutorial on how to integrate Twitter into Android app.  There are some external java libraries over the net that can be used to integrate Twitter into Android app, but they lack of good documentation and tutorial on how to use it on Android. So i  made my own implementation using  Twitter4j and oauth-signpost library. In this tutorial, i create one sample Android project to show how to connect to Twitter, save its token and username on shared preferences so it can be used later to post status to Twitter.

Update 13 Feb 2014:

Updated version of Android-Twitter library available on my new repo on Github, please use this new library for  compatibility with new Twitter REST API v.1.1

New Android-Twitter Library

===================================

I. Register Twitter Application

To enable user to post status to Twitter, first you have to create one Twitter application. Simply go to Twitter Apps page and register your application. Fill the ‘Application Name‘ with your desired name, it has to be unique. If you use a name that already exist (taken by someone), you’ll get a warning message.  On ‘Application Type’ option, choose ‘Browser’ , and because its a browser type application but used in mobile application, you can set it’s callback url on ‘Callback URL‘ field  with any url you want. On ‘Default Access type’, choose ‘Read and Write‘ to enable access to post status. Click save and if all things going well, you’ll get a page showing your consumer key and secret key. Copy these two keys for later use in Android app.

II. Android Integration

To integrate Twitter into Android app, you need four external jar files from two different libraries, Twitter4j and oauth-signpost. You can download latest version from Twitter4j download page or use the one included in my sample project (twitter4j-core-2.1.6.jar) and oauth-signpost from oauth-signpost download page (signpost-core-1.2.1.1.jar, signpost-commonshttp4-1.2.1.1.jar, signpost-jetty6-1.2.1.1.jar). Add the four external jars into your Android project (on Eclipse, right click on your project->properties then on Java Build Path click Add External JARs button to select files)

In my sample project, i create three helper classes (TwitterApp.java,  TwitterDialog.java, and TwitterSession.java) to handle authentication using Webview Dialog and session handler to save token and username on Shared Preferences.

Code implementation

1. Twitter Connection (TestConnection.java)

This example shows how to connect to Twitter, display webview dialog to authorize user then save user’s token and username on shared preference for later use.

public class TestConnect extends Activity {
	private TwitterApp mTwitter;
	private CheckBox mTwitterBtn;

	private static final String twitter_consumer_key = "xxx";
	private static final String twitter_secret_key = "xxx";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		mTwitterBtn	= (CheckBox) findViewById(R.id.twitterCheck);

		mTwitterBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onTwitterClick();
			}
		});

		mTwitter 	= new TwitterApp(this, twitter_consumer_key,twitter_secret_key);

		mTwitter.setListener(mTwLoginDialogListener);

		if (mTwitter.hasAccessToken()) {
			mTwitterBtn.setChecked(true);

			String username = mTwitter.getUsername();
			username		= (username.equals("")) ? "Unknown" : username;

			mTwitterBtn.setText("  Twitter (" + username + ")");
			mTwitterBtn.setTextColor(Color.WHITE);
		}

		Button goBtn = (Button) findViewById(R.id.button1);

		goBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(TestConnect.this, TestPost.class));
			}
		});
	}

	private void onTwitterClick() {
		if (mTwitter.hasAccessToken()) {
			final AlertDialog.Builder builder = new AlertDialog.Builder(this);

			builder.setMessage("Delete current Twitter connection?")
			       .setCancelable(false)
			       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			        	   mTwitter.resetAccessToken();

			        	   mTwitterBtn.setChecked(false);
			        	   mTwitterBtn.setText("  Twitter (Not connected)");
			        	   mTwitterBtn.setTextColor(Color.GRAY);
			           }
			       })
			       .setNegativeButton("No", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                dialog.cancel();

			                mTwitterBtn.setChecked(true);
			           }
			       });
			final AlertDialog alert = builder.create();

			alert.show();
		} else {
			mTwitterBtn.setChecked(false);

			mTwitter.authorize();
		}
	}

	private final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
		@Override
		public void onComplete(String value) {
			String username = mTwitter.getUsername();
			username		= (username.equals("")) ? "No Name" : username;

			mTwitterBtn.setText("  Twitter  (" + username + ")");
			mTwitterBtn.setChecked(true);
			mTwitterBtn.setTextColor(Color.WHITE);

			Toast.makeText(TestConnect.this, "Connected to Twitter as " + username, Toast.LENGTH_LONG).show();
		}

		@Override
		public void onError(String value) {
			mTwitterBtn.setChecked(false);

			Toast.makeText(TestConnect.this, "Twitter connection failed", Toast.LENGTH_LONG).show();
		}
	};
}

First, create an instance of  TwiterApp class with context, consumer key and secret key as constructor’s parameters. Use hasAccessToken() method to check if there is previously saved session. If there is no saved session, call authorize() to open authorization dialog. If user allows the connection, his access token and user name will be saved on shared preferences. You can setup listener to handle on success and on error event by creating an instance of TwDialogListener and pass it to setListener() method.

2. Post Status (TestPost.java)

This example shows how to post Twitter status. If there is no previously saved session, display authorization dialog to allow user authorize the connection then post status using different thread.

public class TestPost extends Activity {
	private TwitterApp mTwitter;
	private CheckBox mTwitterBtn;
	private String username = "";
	private boolean postToTwitter = false;

	private static final String twitter_consumer_key = "xxxx";
	private static final String twitter_secret_key = "xxxx";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.post);

		Button postBtn 				= (Button) findViewById(R.id.button1);
		final EditText reviewEdit   = (EditText) findViewById(R.id.revieew);

		postBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String review = reviewEdit.getText().toString();

				if (review.equals("")) return;

				postReview(review);

				if (postToTwitter) postToTwitter(review);
			}
		});

		mTwitter = new TwitterApp(this, twitter_consumer_key,twitter_secret_key);

		mTwitter.setListener(mTwLoginDialogListener);

		mTwitterBtn	= (CheckBox) findViewById(R.id.twitterCheck);

		mTwitterBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mTwitter.hasAccessToken()) {
					postToTwitter = mTwitterBtn.isChecked();
				} else {
					mTwitterBtn.setChecked(false);
					mTwitter.authorize();
				}
			}
		});

		if (mTwitter.hasAccessToken()) {
			username 	= mTwitter.getUsername();
			username	= (username.equals("")) ? "No Name" : username;

			mTwitterBtn.setText("  Twitter  (" + username + ")");
		}
	}

	private void postReview(String review) {
		//post to server

		Toast.makeText(this, "Review posted", Toast.LENGTH_SHORT).show();
	}

	private void postToTwitter(final String review) {
		new Thread() {
			@Override
			public void run() {
				int what = 0;

				try {
					mTwitter.updateStatus(review);
				} catch (Exception e) {
					what = 1;
				}

				mHandler.sendMessage(mHandler.obtainMessage(what));
			}
		}.start();
	}

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			String text = (msg.what == 0) ? "Posted to Twitter" : "Post to Twitter failed";

			Toast.makeText(TestPost.this, text, Toast.LENGTH_SHORT).show();
		}
	};
	private final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
		@Override
		public void onComplete(String value) {
			username 	= mTwitter.getUsername();
			username	= (username.equals("")) ? "No Name" : username;

			mTwitterBtn.setText("  Twitter  (" + username + ")");
			mTwitterBtn.setChecked(true);

			postToTwitter = true;

			Toast.makeText(TestPost.this, "Connected to Twitter as " + username, Toast.LENGTH_LONG).show();
		}

		@Override
		public void onError(String value) {
			mTwitterBtn.setChecked(false);

			Toast.makeText(TestPost.this, "Twitter connection failed", Toast.LENGTH_LONG).show();
		}
	};
}

Update 2011-10-01

– Fix authorization failed bug when attempt to authorize after logging out. This was caused by an exception (java.lang.IllegalStateException: consumer key/secret pair already set) was thrown by setOauthConsumer(consumerKey,secretKey) method of Twitter class. This method should be called once.

[ad]

You can download  the source code here (with external jars) or via github here

Facebooktwitterredditpinterestlinkedinmailby feather

Related posts:

  1. How to Use Facebook SDK to Post Status From Android
  2. How to Send Image to Twitpic from Android
  3. How to Create QuickAction Dialog in Android
  4. How to Use Foursquare API on Android Application

Filed Under: Android, Featured Articles, Information Technology, Programming Tagged With: Android, api, post status, status, timeline, twitter, twitter4j

About Lorensius Londa

Passionate web and mobile application developer. Co-founder of TRUSTUDIO, loves programming, Android, aviation, travelling, photography, coffee and gym mania.

Reader Interactions

Comments

  1. Sumant says

    February 28, 2011 at 8:53 pm

    Hi,

    Thanks very much it help me lot to solve my problem.

    Reply
    • lorenz says

      March 1, 2011 at 6:52 pm

      You’re welcome ……

      Reply
      • Andy says

        March 2, 2011 at 12:35 am

        Can Only TwitterApp.java itself can post the message on twitter.

        Where is the password getting updated ?

        Reply
  2. Mark Zukerberg says

    March 11, 2011 at 9:05 am

    This tutorial is pretty awesome. I m using it in the android facebook app to connect to twitter

    Reply
    • ab says

      April 26, 2011 at 4:06 am

      Hey are you using Sugree’s API?

      Reply
  3. supertoonz says

    March 13, 2011 at 1:16 pm

    i cant connect twitter

    when i download yr app

    i add external jar then copy and replace
    my cunsumer key and consumer secret in yr app but when i run emulator and click
    checkbox to connect , app show “Twitter connection failed”
    because mTwitter.hasAccessToken() = false

    Login dilaog is not show

    Reply
    • Souksou says

      March 13, 2011 at 11:09 pm

      Hey supertoonz,

      I have the same problem with you.
      I resolved this problem, i forget to change the callback url.

      Try this.

      Thanks for this tutorial !

      ++

      Reply
      • supertoonz says

        March 15, 2011 at 11:03 pm

        thank you . it’s work.

        Reply
        • Uzair says

          March 21, 2011 at 10:09 pm

          Hey super,

          what should be the callback url?

          Reply
          • Lohithadas says

            March 22, 2011 at 2:35 pm

            Have you got it working..I am also having the same problem..

          • lorenz says

            March 23, 2011 at 9:09 pm

            Hi, you can put any url as callback url

  4. Chamith Weerasinghe says

    March 22, 2011 at 7:44 pm

    I also get the same prob.
    What is mean by callback Url.

    Reply
    • lorenz says

      March 23, 2011 at 9:12 pm

      Callback url is used on web based app. If your app is a mobile application, you can put any url as Callback URL.

      Reply
  5. abhirav says

    March 24, 2011 at 12:33 pm

    Is there any way of deleting the recently posted status in twitter from android..?

    Reply
  6. Jahanzaib says

    March 26, 2011 at 1:41 pm

    i am also getting “Twitter connection failed” on device but its working correct on emualator. . . Can you tell me What the mistake i am doing ? ? ?

    Thanks in advance.

    Reply
    • bhm says

      April 13, 2011 at 11:16 pm

      same prob

      Reply
  7. PvTai says

    April 5, 2011 at 2:06 pm

    Thanks so much, i’m try it :).

    Reply
  8. PvTai says

    April 5, 2011 at 4:48 pm

    I worked but method getAccessToken() return “null” . I trying but not work, please help me. I was post my project on mediafire: http://www.mediafire.com/?0vard7jimbco3rd

    Reply
    • PvTai says

      April 5, 2011 at 4:52 pm

      I changed call back URL but don’t work.

      Reply
      • lorenz says

        April 6, 2011 at 8:32 am

        Hi PvTai, on web settings, have set the ‘Application Type’ to browser? and also on TwitterApp.java, use ” public static final String CALLBACK_URL = “twitterapp://connect” ” instead of public static final String CALLBACK_URL = “http://twitter.com/#!/QGSVietnam”

        Reply
        • PvTai says

          April 6, 2011 at 9:42 am

          Ok, I have done. thanks.
          but I see you said “you can put any url as Callback URL.”
          So why now are you saying to use ” public static final String CALLBACK_URL = “twitterapp://connect” ” instead of public static final String CALLBACK_URL = “http://twitter.com/#!/QGSVietnam”. I really do not understand about this issue.
          You can say more to you, please.

          Reply
  9. Deepa says

    April 7, 2011 at 6:50 pm

    Hi..
    Article is helpful to begineers like me but when i download ur app i hve error in TwitterApp.java in the CommonsHttpOAuthConsumer and OAuthProvider java class. it ask me to create new class with this name.. how to solve this problem?

    Reply
  10. snowind says

    April 11, 2011 at 4:19 pm

    Hi, I have downloaded yr app and it works.

    Now I am trying to learn it and writing my app. While I have a question, why do u use Handler in TwitterApp.java? Why don’t u authorize directly?

    Reply
    • snowind says

      April 12, 2011 at 3:20 am

      I tried to use startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)) and onNewIntent(Intent) to get the verifier. But when I ran it on the TwitterApp.java, it turned out to be NullnotFound? Can you help me

      Reply
    • lorenz says

      April 14, 2011 at 9:05 am

      Thats a network operation and may block the main process, so its better to separate it from main thread.

      Reply
  11. new_user says

    April 13, 2011 at 1:58 pm

    Hi,
    thanks for this tutorial, bt im unable see the tweets sent on my twitter account,plz help

    Reply
  12. new_user says

    April 14, 2011 at 12:38 am

    Hi,
    i solved the issue, i just commented these lines in Testost ie.,
    if (review.equals(“”)) return;
    postReview(review);
    if (postToTwitter) postToTwitter(review);

    and called postToTwitter instead,
    hope this helps sumbody,
    thanks

    Reply
  13. ab says

    April 26, 2011 at 4:07 am

    Hey are you using Sugree’s SDK?

    Reply
  14. ab says

    April 26, 2011 at 4:08 am

    Hey are you using sugree’s SAL?

    Reply
  15. got error says

    April 26, 2011 at 4:11 am

    Hi i got this error:

    04-25 14:07:51.188: WARN/System.err(322): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Received authentication challenge is null

    Can you help me?
    Thanks

    Reply
    • lorenz says

      April 28, 2011 at 8:09 pm

      Hi, the problem caused by oauth-signpost lib. I never got that problem. You may look at this issue: http://code.google.com/p/oauth-signpost/issues/detail?id=21

      Reply
  16. new_user says

    April 26, 2011 at 4:12 pm

    Hi lorenz,

    can you get sugree’s sdk working, as im unable to post tweets using his code.

    Reply
  17. Gosu says

    April 26, 2011 at 4:42 pm

    Can I sign out from the twitter account using your TwitterApp class?

    Reply
    • lorenz says

      April 28, 2011 at 8:13 pm

      You don’t have to signout, there is no session like facebook. Just delete the token using resetAccessToken method on TwitterApp.java

      Reply
      • Naga Shankar says

        June 7, 2011 at 6:49 pm

        Hi Lorenz,

        This seems to be wrong. Because after i deleted the access token and restarted the application and again tryed to sign in, i still can see the user profile picture and “Signout” option in Twitter WebView Page(on top right corner). And in that web page there are no editfields to receive fresh username and password.

        I am guessing that Twitter Webpage has stored there credentials in it’s own shared preferences.

        How can we completely clear all login info so that it wont show those details again?

        Reply
        • lorenz says

          June 16, 2011 at 2:59 pm

          Hi Naga,

          You can use webview’s clearCache() method to delete all caches.

          Reply
  18. Surya says

    April 27, 2011 at 2:07 am

    Hi,
    Thanks for providing the information. I tried working on it. When I connect it to the mobile phone. and Press the Tweet Post button, it does not initiate anything. as in No Response. And it is mentioned that the twitter account is also Not connected. the Callback Url is the new value only. It would be helpful of you.

    Reply
    • lorenz says

      April 28, 2011 at 8:19 pm

      Did you change the callback url constant in TwitterApp.java ?

      Reply
      • Surya says

        April 28, 2011 at 10:38 pm

        the callback url is “twitterapp: //connect”… Do you want me to change this callback url?

        Reply
        • lorenz says

          May 2, 2011 at 10:44 pm

          Nope, don’t change it

          Reply
  19. Pankaj says

    April 27, 2011 at 1:37 pm

    Hi lorenz……
    Thanks a lot it works…

    Reply
  20. harsha says

    April 27, 2011 at 6:19 pm

    i try your code ,it works fine could u pls tell how to add filter API in this apps.
    pls help.

    Reply
  21. SEDHURAJA says

    April 28, 2011 at 2:04 pm

    Hey ppl , I m not able to debug !!! i m getting Twitter Connection Failed ! I changed callback url !!
    I m not getting the dialog box where we have to enter the username password . pls post any perfectly working code !!

    Reply
    • lorenz says

      April 28, 2011 at 8:23 pm

      Don’t change the callback url in TwitterApp.java

      Reply
      • Piyush says

        May 8, 2011 at 4:04 pm

        Hi, i am trying your code and i have consumer as well secret key but all the time i am getting System error oauth.singpost.exception.OAuhtCommunicationException: communication with the service provider failed: http//twitter.com/oaut/request_token, i tried to resolve it but i can’t figure it out.

        Reply
    • sam says

      May 24, 2011 at 4:26 pm

      Did you get it working? i am having the same problem.

      Reply
  22. gianpaolo says

    April 30, 2011 at 2:04 am

    hello!
    thank you very much for this article.

    I have 2 question:
    1)when “deny” is pressed, should the webview be dismissed or do I have to add some code?
    2)my boss wants me to write an application that can post on twitter without user interaction (I have login and password), but I dont think it is possible anymore, since now we have to deal with oauth. Am I right?

    regards

    Reply
  23. Sameer says

    April 30, 2011 at 7:50 am

    Hi everyone,
    I would like to close the authorize dialog box, when user clicks on “No Thanks.” How can I make it happen.

    thanks

    Sameer

    Reply
  24. SEDHURAJA says

    May 4, 2011 at 12:53 pm

    still i m facing the same prob !! so please anyone post perfectly working code !!

    Reply
  25. Piyush says

    May 8, 2011 at 10:33 pm

    I figure it out its DefaultOAuther use CommonsHttpOAuth but still getting 401 error.

    Reply
    • lorenz says

      May 18, 2011 at 7:42 am

      Hi Piyush, coud you give me your sampe project (delete the keys first)?

      Reply
  26. Joe says

    May 14, 2011 at 2:17 am

    Thank you very, very much for a clear and concise description on how to get this working. Well done.

    Reply
  27. Nandagopal says

    May 15, 2011 at 4:19 pm

    Hi,

    I am trying to integrate the Twitter in to my App. I registered the app and got the consumer key as well as the secret key too. Whenever i tried to refer those in the code and execute the app, it gives me the following error.

    Seems like a some communication exception

    05-15 13:57:37.988: WARN/System.err(488): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://twitter.com/oauth/request_token
    05-15 13:57:37.988: WARN/System.err(488): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    05-15 13:57:37.998: WARN/System.err(488): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    05-15 13:57:37.998: WARN/System.err(488): at net.xxx.android.TwitterApp$2.run(TwitterApp.java:117)
    05-15 13:57:37.998: WARN/System.err(488): Caused by: java.io.FileNotFoundException: http://twitter.com/oauth/request_token
    05-15 13:57:38.007: WARN/System.err(488): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1061)
    05-15 13:57:38.007: WARN/System.err(488): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    05-15 13:57:38.017: WARN/System.err(488): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    05-15 13:57:38.017: WARN/System.err(488): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    05-15 13:57:38.017: WARN/System.err(488): … 2 more

    Reply
    • lorenz says

      May 18, 2011 at 7:41 am

      Hi, could you give me your sample project? (delete your key first)

      Reply
      • Ahmed El-Sharkasy says

        June 5, 2011 at 2:33 am

        how can i send it to you? via mail?

        Reply
  28. fou says

    May 17, 2011 at 8:54 pm

    thank you it is very helpful. But I didn’t see my statu twitter.

    Reply
  29. gayathri says

    May 22, 2011 at 8:44 pm

    Hi,

    I am learning android from learning android book . Thanks for this wonderful post . Can i connect to twitter without registering my application , just by calling the twitter constructor and update status as i don’t have a url to register.

    Reply
  30. sam says

    May 24, 2011 at 3:32 pm

    hi, when i try to authorize, dialog box does not open, instead i get twitter connection failed message. My callback url is “twitterapp://connect” . I changed DefaultOAuther to CommonsHttpOAuth .I cant figure out what i am doing wrong.

    Reply
    • lorenz says

      May 24, 2011 at 7:03 pm

      Could you provide the error log from logcat ?

      Reply
  31. sam says

    May 24, 2011 at 6:19 pm

    i am using your project. i dnt integrate it into my app yet

    Reply
  32. sam says

    May 24, 2011 at 7:33 pm

    this is the logcat:

    05-24 17:28:03.838: WARN/DefaultRequestDirector(2359): Authentication error: Unable to respond to any of these challenges: {}

    05-24 17:28:03.838: INFO/global(2359): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.

    05-24 17:28:03.848: DEBUG/TwitterApp(2359): Failed to get request token

    05-24 17:28:03.848: WARN/System.err(2359): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.

    05-24 17:28:03.848: WARN/System.err(2359): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239)

    05-24 17:28:03.848: WARN/System.err(2359): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)

    05-24 17:28:03.848: WARN/System.err(2359): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)

    05-24 17:28:03.848: WARN/System.err(2359): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:118)

    05-24 17:28:03.868: DEBUG/SurfaceFlinger(109): Layer::setBuffers(this=0x857658), pid=2359, w=1, h=1

    05-24 17:28:03.868: DEBUG/SurfaceFlinger(109): Layer::setBuffers(this=0x857658), pid=2359, w=1, h=1

    05-24 17:28:03.868: WARN/InputManagerService(109): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@465751b8

    please note that the application is running fine on emulator. i get this exception when i try to run it on device. I tested it on HTC magic and HTC desire

    Reply
    • lorenz says

      June 2, 2011 at 9:12 pm

      Hi, you may refer to this discussion:

      http://code.google.com/p/oauth-signpost/wiki/TwitterAndSignpost

      Reply
  33. Ahmed El-Sharkasy says

    June 5, 2011 at 2:32 am

    Thanks a lot for this beneficial tutorial.

    I have a problem that when the pin is displayed in the twitter web view , i am trapped and cant return to my application
    do i have to add something to get this working or am missing something here?

    waiting for your reply

    Reply
    • lorenz says

      June 5, 2011 at 2:10 pm

      Hi Ahmed, i’m not using pin based auth in this tutorial. have u tried the code in this tutorial ?

      Reply
  34. Karan says

    June 9, 2011 at 3:38 am

    Hi lorenz ,
    I hace downloaded your application but whenever i run and click on twitter i get a toast twitter connection failed….please help guys

    Reply
    • lorenz says

      June 16, 2011 at 3:02 pm

      Have u done all the settings correctly? any error log info?

      Reply
  35. frx08 says

    June 13, 2011 at 8:16 pm

    for all those who receive the 401 error: check if the time on the device is set correctly, otherwise it is impossible to receive the authentication for the fact that the validity has expired
    😉

    Reply
  36. Hauki says

    June 17, 2011 at 10:39 pm

    Hey, thanks for great tutorial. I have only changed DefaultOAuther to CommonsHttpOAuth and added my own keys. The problem is that t wont work on my device over wifi, but when going over 3G or on the emulator it works just fine.

    It just displays loding for a while after i’ve put in my mail and passwor, then it shows “Twitter connection failed”.

    Logcat:
    06-17 17:30:26.881: DEBUG/Twitter-WebView(1429): Loading URL: http://twitter.com/oauth/authorize

    06-17 17:30:39.643: DEBUG/dalvikvm(1429): GC_CONCURRENT freed 1052K, 50% free 3569K/7047K, external 2078K/2137K, paused 2ms+3ms

    06-17 17:30:39.647: DEBUG/webviewglue(1429): nativeDestroy view: 0x36b038

    06-17 17:30:49.815: DEBUG/Twitter-WebView(1429): Page error: The server failed to communicate. Try again later.

    06-17 17:30:49.842: DEBUG/Twitter-WebView(1429): Loading URL: http://twitter.com/oauth/authorize

    Reply
  37. tech says

    June 18, 2011 at 10:11 am

    hi, i cant seem to go past beyond this line

    authUrl = mHttpOauthprovider.retrieveRequestToken(mHttpOauthConsumer, CALLBACK_URL);

    in TwitterApp

    it just hangs

    Reply
  38. Andrej says

    June 20, 2011 at 5:00 pm

    looks promissing, must try. Actually i am surprised that there are no good samples how to do main operations with Twitter and Facebook …

    Reply
  39. Maruba says

    June 22, 2011 at 6:19 pm

    Hey,
    i have a problem with your Source code, but i dont know how to fix it, can you help me please?

    i already tried it with ‘https://api.twitter.com’ instead of ‘http://twitter.com’ ang got the same result

    D/TwitterApp( 1337): Failed to get request token
    W/System.err( 1337): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://twitter.com/oauth/request_token
    W/System.err( 1337): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    W/System.err( 1337): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    W/System.err( 1337): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    W/System.err( 1337): Caused by: java.io.FileNotFoundException: http://twitter.com/oauth/request_token
    W/System.err( 1337): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)
    W/System.err( 1337): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    W/System.err( 1337): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    W/System.err( 1337): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    W/System.err( 1337): … 2 more

    Reply
  40. Barril says

    June 25, 2011 at 8:11 am

    Hi!!

    Thanks for the awesome twitter app! I only have one question: Why it has to be type “browser”?

    A twitter app for android isn’t a client type?

    Thanks!

    Best Regards,

    Reply
  41. Ankit Shah says

    June 29, 2011 at 7:03 pm

    Thanks for step-by-step process and sample code…

    But i have question regarding “Application Type” – as we have implemented twitter related stuff in iPhone where it requires “Application Type” as “Client” – now if i change to “Browser” iPhone implementation stop working… Any help or pointer on this will be appreciated.

    Reply
  42. Kikoso says

    July 9, 2011 at 12:42 am

    This is definitely not working. Twitter has not only changed the addresses, plus now is necessary to register a domain to access the application. I haven’t been able yet to post a solution, hope to make it soon 🙂

    Reply
  43. pvu says

    July 22, 2011 at 3:30 am

    I’m getting similar errors like one of the members from above. I’ve been on this for awhile, this will be my first time connecting to the internet from an android app. I’m sure it has to do with my Twitter & code configurations. So, your help is greatly appreciated.

    Here’s the error when run app example:
    ‘twitter (not connected)’
    Here’s the error after pressing post:
    ‘post to twitter failed’

    Let me know if you need more info. Thanks

    Reply
    • lorenz says

      July 22, 2011 at 7:38 am

      Hello, could you give me the log cat error?

      Reply
      • pvu says

        July 26, 2011 at 1:20 am

        I hope you don’t mind the long log:

        [2011-07-19 19:11:47 – testconnect] ——————————
        [2011-07-19 19:11:47 – testconnect] Android Launch!
        [2011-07-19 19:11:47 – testconnect] adb is running normally.
        [2011-07-19 19:11:47 – testconnect] Performing net.londatiga.android.TestConnect activity launch
        [2011-07-19 19:11:47 – testconnect] Automatic Target Mode: using existing emulator ’emulator-5554′ running compatible AVD ‘sdk2_1api7′
        [2011-07-19 19:11:47 – testconnect] WARNING: Application does not specify an API level requirement!
        [2011-07-19 19:11:47 – testconnect] Device API version is 7 (Android 2.1-update1)
        [2011-07-19 19:11:47 – testconnect] Uploading testconnect.apk onto device ’emulator-5554′
        [2011-07-19 19:11:49 – testconnect] Installing testconnect.apk…
        [2011-07-19 19:12:01 – testconnect] Success!
        [2011-07-19 19:12:02 – testconnect] Starting activity net.londatiga.android.TestConnect on device emulator-5554
        [2011-07-19 20:12:24 – testconnect] ——————————
        [2011-07-19 20:12:24 – testconnect] Android Launch!
        [2011-07-19 20:12:24 – testconnect] adb is running normally.
        [2011-07-19 20:12:24 – testconnect] Performing net.londatiga.android.TestConnect activity launch
        [2011-07-19 20:12:24 – testconnect] Automatic Target Mode: using existing emulator ’emulator-5554′ running compatible AVD ‘sdk2_1api7’
        [2011-07-19 20:12:25 – testconnect] WARNING: Application does not specify an API level requirement!
        [2011-07-19 20:12:25 – testconnect] Device API version is 7 (Android 2.1-update1)
        [2011-07-19 20:12:28 – testconnect] Application already deployed. No need to reinstall.
        [2011-07-19 20:12:28 – testconnect] Starting activity net.londatiga.android.TestConnect on device emulator-5554
        [2011-07-19 20:12:31 – testconnect] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=net.londatiga.android/.TestConnect }
        [2011-07-19 20:12:31 – testconnect] ActivityManager: Warning: Activity not started, its current task has been brought to the front

        Reply
        • lorenz says

          July 31, 2011 at 9:12 pm

          Hi pvu, this is not what i ment. Copy the logcat error from ddms.

          Reply
          • pvu says

            August 6, 2011 at 10:21 am

            I sent it out twice, but it’s not showing up in the forum. Hmmm, maybe it was too long. Let me know if I can send an attachment to you.

  44. Muhammad Rashid says

    July 27, 2011 at 5:51 pm

    Hi,
    Thanks for this awesome post. It is very helpful. Would you like to tell, is it possible to post all these three things (some Text + any image from sd card + any url or link ) in a single post.

    Kind regards,
    Muhammad Rashid

    Reply
    • lorenz says

      July 31, 2011 at 9:33 pm

      Hi, to post image, you have to use third party image service api such as twitpic.

      Reply
  45. Lexs194 says

    August 1, 2011 at 10:13 am

    it work,.but after click Authorize app,.
    it freezee,. can’t came back to my app? what wrong,.? (sorry my english)
    this logcat :

    07-31 23:06:23.883: DEBUG/TwitterApp(363): Request token url http://twitter.com/oauth/authorize?oauth_token=qtKQr3Pr7irHiQXwkPBLo2PUmxQHnqXSgVa24Gh0IU
    07-31 23:06:24.453: DEBUG/Twitter-WebView(363): Loading URL: http://twitter.com/oauth/authorize?oauth_token=qtKQr3Pr7irHiQXwkPBLo2PUmxQHnqXSgVa24Gh0IU
    07-31 23:06:37.735: DEBUG/dalvikvm(363): GC freed 5910 objects / 397872 bytes in 199ms
    07-31 23:06:42.314: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44e49388
    07-31 23:06:52.754: WARN/KeyCharacterMap(363): No keyboard for id 0
    07-31 23:06:52.763: WARN/KeyCharacterMap(363): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
    07-31 23:07:08.004: DEBUG/dalvikvm(363): GC freed 6289 objects / 527216 bytes in 197ms
    07-31 23:07:08.143: DEBUG/webviewglue(363): nativeDestroy view: 0x32d490
    07-31 23:07:08.473: ERROR/webcoreglue(363): The real object has been deleted
    07-31 23:07:08.495: ERROR/webcoreglue(363): The real object has been deleted
    07-31 23:07:08.544: ERROR/webcoreglue(363): The real object has been deleted
    07-31 23:07:08.644: DEBUG/Twitter-WebView(363): Loading URL: https://twitter.com/oauth/authorize
    07-31 23:07:11.205: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44e7c4b0

    Reply
  46. Kiran Kala says

    August 2, 2011 at 6:12 pm

    Hi Lorenz..!

    I am getting the following exception while running the app in DEVICE, but where as in EMULATOR it’s working properly..

    oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Received authentication challenge is null

    I nedd the solution as early as possible

    Kiran Kala

    Reply
    • lorenz says

      August 6, 2011 at 12:07 am

      Hi Kiran, i don’t know what exactly cause the problem. Error ‘Received authentication challenge is null’ may raised when
      java.net.HttpURLConnection receives a 401 (Unauthorized) from the server. Do you use different sdk on emulator and device?

      Reply
  47. Kiran Kala says

    August 4, 2011 at 11:12 am

    Hi Lorenz..!

    I am eagerly waiting for your response..,and I have one more query
    i.e.,whether TWITTER will work in Android 2.1 or not, because..My application is working for 2.2 but not its not supported it 2.1, when I tried to execute in 2.1 I am getting the above error..

    Kiran Kala

    Reply
  48. Sujit says

    August 4, 2011 at 3:21 pm

    updateStaus not working using twitter4j-core2.1.6. and throws an exception is there any change that i need to make

    Reply
  49. Andi says

    August 5, 2011 at 10:19 pm

    Hi guys! I have the same issue as Kiran Kala. 2.2 and above is working and on a 2.1 device or emulator is not. Does somebody have any idea why is this happening?

    Thanks!
    Andi

    Reply
  50. Shawn says

    August 7, 2011 at 1:50 pm

    Thanks for the guide. I thought I would post my experience.

    1) Didn’t work with latest twitter4j-2.2.4 build. Sorry, I didn’t keep the error output, but the problems seems to be that package paths have changed. I used the 2.1.6 branch bundled in the ExtJars file to resolve the problem.

    2) Instructions for setting application type have changed. There is no more option for setting application type to Browser. Instead you just need to specify a callback URL or you will see this error in the debug output.

    java.io.FileNotFoundException: https://api.twitter.com/oauth/request_token

    I found this message in a TCP packet capture.

    /oauth/request_token Desktop applications only support the oauth_callback value ‘oob’

    Here is some additional information.
    http://groups.google.com/group/twitter-development-talk/browse_thread/thread/0f744fe83fd9ef90?pli=1
    https://dev.twitter.com/discussions/282

    Thanks for the tutorial. Only took an hour for me to add Twitter feature with your help.

    Reply
    • lorenz says

      August 9, 2011 at 8:53 pm

      Hi Shawn, thanx for sharing your experience, this is really informative and helpfull.

      Reply
  51. veljko says

    August 15, 2011 at 6:48 pm

    hey, im using you app and cant post message to twitter. im getting: “Post to twitter failed”

    in log cat i get only this:

    08-15 13:46:34.570: WARN/KeyCharacterMap(2253): Can’t open keycharmap file
    08-15 13:46:34.570: WARN/KeyCharacterMap(2253): Error loading keycharmap file ‘/system/usr/keychars/AT_Translated_Set_2_keyboard.kcm.bin’. hw.keyboards.65539.devname=’AT Translated Set 2 keyboard’
    08-15 13:46:34.570: WARN/KeyCharacterMap(2253): Using default keymap: /system/usr/keychars/qwerty.kcm.bin

    and this:

    08-15 13:45:32.740: DEBUG/UpdaterService(1347): Updater ran.
    08-15 13:45:33.220: ERROR/UpdaterService(1347): Updater.run exception: winterwell.jtwitter.TwitterException: 401 Unauthorized http://twitter.com/statuses/friends_timeline.json

    any idea?

    Reply
    • lorenz says

      August 18, 2011 at 3:19 pm

      Seems like you had problem with authorization, did you finish the authorization process?

      Reply
      • veljko says

        August 18, 2011 at 6:54 pm

        yes i did…i got this working, i had a problem with proxy server access.

        Thx for quick answer.

        Anyway, i need to have option of changing twitter account. How do I do that?

        I’ve add a new button, and on click, im doing this:

        mTwitter.resetAccessToken();
        mTwitter.configureToken();
        mTwitter.authorize();

        after seting up new user name and password in authorize dialog, im getting “Twitter connecection failed”

        in logcat im getting:

        08-18 13:44:34.109: WARN/System.err(1941): java.lang.IllegalStateException: consumer key/secret pair already set.
        08-18 13:44:34.109: WARN/System.err(1941): at twitter4j.TwitterOAuthSupportBaseImpl.setOAuthConsumer(TwitterOAuthSupportBaseImpl.java:234)
        08-18 13:44:34.109: WARN/System.err(1941): at twitter4j.Twitter.setOAuthConsumer(Twitter.java:54)
        08-18 13:44:34.109: WARN/System.err(1941): at com.tweeter.TwitterApp.configureToken(TwitterApp.java:74)
        08-18 13:44:34.109: WARN/System.err(1941): at com.tweeter.TwitterApp$3.run(TwitterApp.java:152)

        How do I solve that?

        Hope for quick response.

        Reply
        • lorenz says

          August 22, 2011 at 11:19 pm

          Hi, have u tried to create new instance of TwitterApp ?

          Reply
          • veljko says

            August 23, 2011 at 4:26 am

            Hey, yes i did.

            This code runs in moment when im logged on twitter with one account. When i click on “change account” button, i need to log out, and sign in as a different user…You know what i mean?

            in changeAccount onClickListener i do this:

            mTwitter = null;

            mTwitter = new TwitterApp(getBaseContext(),
            twitter_consumer_key, twitter_secret_key);
            mTwitter.resetAccessToken();

            if (mTwitter.hasAccessToken()) {
            postToTwitter = mTwitterBtn.isChecked();
            } else {
            mTwitterBtn.setChecked(false);
            mTwitter.authorize();

            }

            The logcat gives me this:
            08-22 20:50:21.059: ERROR/AndroidRuntime(278): FATAL EXCEPTION: main
            08-22 20:50:21.059: ERROR/AndroidRuntime(278): android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application

            on line when im calling authorize method. for re-loging in.

            Help.

          • lorenz says

            September 4, 2011 at 8:36 pm

            Hi, try to use current activity as the parameter for TwitterApp constructor, new TwitterApp(this).

    • agus khoiruddin says

      November 25, 2011 at 1:36 pm

      same problem here,
      at the fist time when application running, i can do a success login to my acount, and ehen i want to legout and then login again, it become failed to connect to my acount.
      thanks for share before. 🙂

      Reply
      • lorenz says

        November 28, 2011 at 10:25 pm

        I think i’ve solved the problem on my latest repo on github 😉

        Reply
  52. Prayag says

    August 18, 2011 at 6:48 pm

    Not working for me…dont know what happened..assigned my own consumer key and secret key…still not working.says “initializing” and the dialog for authentication doent appear

    Reply
    • lorenz says

      August 22, 2011 at 10:40 pm

      could you give me the log cat message?

      Reply
      • Prayag says

        August 23, 2011 at 5:02 pm

        TOKEN_ERROR failed to get request token Communication with the service provider failed android : http://api.twitter.com/oauth/request_token.

        Reply
  53. Nicolas says

    August 25, 2011 at 5:07 am

    Hi lorenz, it works like a champ! But im having a problem. After I authorize my app on twitter it returns me a PIN… it says i have to go back to my app and type in the given PIN, but… not sure how to do that…

    Thanks,!

    Nico.

    Reply
  54. Nirav says

    August 25, 2011 at 8:42 pm

    My problem is that..my twitter dialog doesnt get disapper after authorization.

    Reply
  55. Yashpal says

    August 27, 2011 at 4:29 pm

    Many thanks Loren’z, your post helped a lot.

    Reply
  56. Andrea says

    August 29, 2011 at 8:23 pm

    Thanks a lot for this lorenz!

    The only problem I run into is that using 2.1 API level after I enter my credentials and try to login a blank page appears and nothing is happening.

    Reply
    • Andrea says

      August 30, 2011 at 12:37 am

      Found my answer!!
      https://dev.twitter.com/discussions/828

      Reply
      • lorenz says

        September 4, 2011 at 8:58 pm

        Hi Andrea, thanx for the info..;)

        Reply
  57. Prayag says

    September 3, 2011 at 1:29 pm

    While Creating an app in twitter there was no option like browser or client,why?

    And the following is my LOGCAT

    09-03 11:32:51.035: DEBUG/TwitterApp(301): Failed to get request token

    09-03 11:32:51.045: WARN/System.err(301): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Host is unresolved: twitter.com:80

    09-03 11:32:51.085: WARN/System.err(301): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)

    09-03 11:32:51.085: WARN/System.err(301): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)

    09-03 11:32:51.095: WARN/System.err(301): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)

    09-03 11:32:51.105: WARN/System.err(301): Caused by: java.net.UnknownHostException: Host is unresolved: twitter.com:80

    09-03 11:32:51.114: WARN/System.err(301): at java.net.Socket.connect(Socket.java:1038)

    09-03 11:32:51.125: WARN/System.err(301): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:62)

    09-03 11:32:51.135: WARN/System.err(301): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)

    09-03 11:32:51.135: WARN/System.err(301): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)

    09-03 11:32:51.155: WARN/System.err(301): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)

    09-03 11:32:51.155: WARN/System.err(301): at oauth.signpost.basic.DefaultOAuthProvider.sendRequest(DefaultOAuthProvider.java:48)
    09-03 11:32:51.185: WARN/System.err(301): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)

    09-03 11:32:51.185: WARN/System.err(301): … 2 more

    09-03 11:32:51.435: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43ef6fc0

    Reply
    • lorenz says

      September 4, 2011 at 9:05 pm

      Hi, Twitter has changed the app settings page, there is no setting for client type anymore. From you logcat, i think the problem was on your network connection.

      Reply
  58. bharadwaj says

    September 11, 2011 at 4:28 pm

    hi..i downloaded this and when i import this to my application and after typing the status message and when i click on twitter button nothing is happening,still its just showing the same main UI…please help me out….

    Reply
    • lorenz says

      September 11, 2011 at 9:51 pm

      Did the internet connection work properly?

      Reply
  59. bharadwaj says

    September 15, 2011 at 6:02 pm

    hi..when i am clicking on the twitter check box button to connect to twitter its showing twitter connection failed,and its displaying these messages on the log cat:

    DEBUG/TwitterApp(291): Failed to get request token.
    oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Received authentication challenge is null.

    WARN/System.err(291): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    09-15 16:20:22.083: WARN/System.err(291): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    09-15 16:20:22.093: WARN/System.err(291): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    09-15 16:20:22.093: WARN/System.err(291): Caused by: java.io.IOException: Received authentication challenge is null
    09-15 16:20:22.093: WARN/System.err(291): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1596)
    09-15 16:20:22.103: WARN/System.err(291): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1551)
    09-15 16:20:22.112: WARN/System.err(291): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1273)
    09-15 16:20:22.112: WARN/System.err(291): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:22)
    09-15 16:20:22.122: WARN/System.err(291): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:178)
    09-15 16:20:22.122: WARN/System.err(291): … 2 more
    09-15 16:20:22.163: INFO/NotificationService(60): enqueueToast pkg=net.londatiga.android callback=android.app.ITransientNotification$Stub$Proxy@44de4738 duration=1
    09-15 16:20:22.253: WARN/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44e3ab40

    please help me out…

    Reply
    • lorenz says

      September 20, 2011 at 9:27 pm

      Do you use Android 2.1? Try to use api.twitter.com instead of twitter.com on:

      mHttpOauthprovider = new DefaultOAuthProvider(“http://twitter.com/oauth/request_token”,
      “http://twitter.com/oauth/access_token”,
      “http://twitter.com/oauth/authorize”);

      Reply
  60. Arif Febriyanto says

    September 26, 2011 at 6:32 am

    i always error authencticate at class TestConnect “Twitter Connection Failed”, but if i authenticate at TestPost i always success, why it happen? as i know they use a same function but the result is different? ?

    Reply
    • Arif Febriyanto says

      September 26, 2011 at 7:41 am

      but when i use all of that in my project, two class of them can’t be used, both “Twitter Connection Failed”

      what is the actually reason that error? the problem is confused for me, T_T

      Reply
      • lorenz says

        September 29, 2011 at 8:22 pm

        give me the logcat…

        Reply
  61. jatin says

    September 28, 2011 at 7:32 pm

    hi its shows twitter connection failed

    Reply
    • jatin says

      September 28, 2011 at 7:35 pm

      here is my logcat…

      09-28 14:54:20.094: INFO/ActivityManager(62): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=net.londatiga.android/.TestConnect } from pid 659
      09-28 14:54:20.134: DEBUG/AndroidRuntime(659): Shutting down VM
      09-28 14:54:20.153: DEBUG/dalvikvm(659): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 1ms+1ms
      09-28 14:54:20.174: DEBUG/dalvikvm(659): Debugger has detached; object registry had 1 entries
      09-28 14:54:20.174: INFO/AndroidRuntime(659): NOTE: attach of thread ‘Binder Thread #3’ failed
      09-28 14:54:20.414: DEBUG/dalvikvm(615): GC_EXPLICIT freed 404K, 54% free 2660K/5703K, external 1861K/2137K, paused 598ms
      09-28 14:54:21.194: INFO/ActivityManager(62): Displayed net.londatiga.android/.TestConnect: +1s87ms
      09-28 14:54:25.124: DEBUG/TwitterApp(615): Failed to get request token
      09-28 14:54:25.165: WARN/System.err(615): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://api.twitter.com/oauth/request_token
      09-28 14:54:25.165: WARN/System.err(615): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
      09-28 14:54:25.165: WARN/System.err(615): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
      09-28 14:54:25.173: WARN/System.err(615): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
      09-28 14:54:25.184: WARN/System.err(615): Caused by: java.io.FileNotFoundException: http://api.twitter.com/oauth/request_token
      09-28 14:54:25.184: WARN/System.err(615): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:519)
      09-28 14:54:25.234: WARN/System.err(615): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
      09-28 14:54:25.234: WARN/System.err(615): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
      09-28 14:54:25.234: WARN/System.err(615): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
      09-28 14:54:25.234: WARN/System.err(615): … 2 more
      09-28 14:54:25.673: WARN/InputManagerService(62): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40797598
      09-28 14:54:29.734: DEBUG/dalvikvm(134): GC_EXPLICIT freed 36K, 52% free 2917K/5959K, external 5201K/6458K, paused 49ms

      Reply
      • lorenz says

        September 29, 2011 at 8:47 pm

        Have you set the callback url on application web settings (https://dev.twitter.com/app) ?

        Reply
        • jatin says

          October 4, 2011 at 5:49 pm

          yes sir i did setting call back url as
          https://dev.twitter.com/app

          but still no success, toast appears saving posting to twitter failed

          Reply
          • lorenz says

            October 4, 2011 at 9:51 pm

            Hmmm, did the internet connection work on emulator? From your logcat it seems that you had problem with connection.

          • jatin says

            October 5, 2011 at 11:43 am

            yes sir internet connection is okay there is no issue in connecting to server it successfully login to my twitter acc. but the problem arises only when posting something..please help me m stuck here…

  62. Payal says

    September 30, 2011 at 6:22 pm

    I want to do logout functionality how can I do this.How I release the consumer key and consumer secret key and where I have to return it.

    Reply
    • lorenz says

      October 1, 2011 at 6:43 pm

      Hi Payal, to logout, simply call the resetAccessToken() method. Look at the example on TestConnect.java.

      Reply
  63. Payal says

    September 30, 2011 at 6:24 pm

    Help me for log out option in twitter in android app.

    thanks in advance

    Reply
  64. Huseyin says

    October 5, 2011 at 4:23 pm

    Hi, firstly thanks alot.

    I can login but, when I try to post a message; ıt returns “401:Authentication credentials were missing or incorrect.
    {“error”:”Could not authenticate with OAuth.”,”request”:”\/1\/statuses\/update.json”}
    “.

    What Should I do? My account is readable and writeable…

    Reply
  65. Huseyin says

    October 5, 2011 at 4:27 pm

    hi, firstly thanks alot for codes and article.
    I use your codes, and I can login. When I try to post a message, it returns to me ” 401:Authentication credentials were missing or incorrect.
    {“error”:”Could not authenticate with OAuth.”,”request”:”\/1\/statuses\/update.json”}
    ”

    What Should I Do? My account is readable and writable…

    Reply
  66. Kaushal Sharma says

    October 12, 2011 at 8:44 am

    Hi Lorenz,

    Can you please suggest some for the same “How to Post Twitter Status from Android” with “Sencha Touch” in place of “Android”?

    -Thanks,
    Kaushal

    Reply
    • lorenz says

      October 13, 2011 at 8:44 pm

      Hi Kaushal, sorry i have no experience on Sencha Touch…i can’t give u suggestion 😉

      Reply
  67. Aaron says

    October 28, 2011 at 12:36 am

    Greetings,

    Having an issue w/ TwitterApp.java, line 115:

    authURL = mHttpOauthprovider.retrieveRequestToken(mHttpOauthConsumer, CALLBACK_URL);

    All that my application is doing, is creating the TwitterApp object, setting the listener, checking for accessToken (authorize if not) and then attempting to post.

    If I use https oauth URLs, I get a runtime error:

    OAuthCommunicationsException
    cause- IOException
    detail message- Communication with the service provider failed: Hostname ‘api.twitter.com’ was not verified

    If I use http oauth URLs, I get a different error:

    OAuthCommunicationsException
    cause- FileNotFoundException
    detail message- Communication with the service provider failed: http://api.twitter.com/oauth/request_token

    I’ve searched and searched and cannot find any solution to this. Any assistance would be appreciated.

    Thanks,
    Aaron

    Reply
    • Aaron says

      October 28, 2011 at 1:13 am

      After a little more experimentation, I was able to get by this by entering a valid URL for the Callback URL on dev.twitter.com/apps and placing the exact same URL in my app.

      This only works with http, https still throws the same error.

      Regards,
      Aaron

      Reply
      • lorenz says

        October 30, 2011 at 8:02 am

        Great find..i’ll also try to find the answer..

        Reply
    • lorenz says

      October 30, 2011 at 8:01 am

      api.twitter.com should work on android 2.1 and above. If you use twitter.com/oauth you may have issue with android 2.1. Did u test in emulator or on real device?

      Reply
  68. Doularam says

    November 9, 2011 at 12:35 pm

    11-09 11:04:28.052: W/System.err(620): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Received authentication challenge is null
    11-09 11:04:28.082: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    11-09 11:04:28.092: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    11-09 11:04:28.092: W/System.err(620): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    11-09 11:04:28.102: W/System.err(620): Caused by: java.io.IOException: Received authentication challenge is null
    11-09 11:04:28.142: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
    11-09 11:04:28.142: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
    11-09 11:04:28.162: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
    11-09 11:04:28.182: W/System.err(620): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:22)
    11-09 11:04:28.192: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:178)
    11-09 11:04:28.202: W/System.err(620): … 2 more
    11-09 11:04:28.542: W/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44fc5bf0

    Reply
  69. Doularam says

    November 9, 2011 at 12:40 pm

    11-09 11:04:28.052: W/System.err(620): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Received authentication challenge is null
    11-09 11:04:28.082: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    11-09 11:04:28.092: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    11-09 11:04:28.092: W/System.err(620): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    11-09 11:04:28.102: W/System.err(620): Caused by: java.io.IOException: Received authentication challenge is null
    11-09 11:04:28.142: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
    11-09 11:04:28.142: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
    11-09 11:04:28.162: W/System.err(620): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
    11-09 11:04:28.182: W/System.err(620): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:22)
    11-09 11:04:28.192: W/System.err(620): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:178)
    11-09 11:04:28.202: W/System.err(620): … 2 more
    11-09 11:04:28.542: W/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44fc5bf0

    1) internet connection is works properly.

    2)I Tried to use api.twitter.com instead of twitter.com on:

    mHttpOauthprovider = new DefaultOAuthProvider(”http://twitter.com/oauth/request_token”,
    “http://twitter.com/oauth/access_token”,
    “http://twitter.com/oauth/authorize”);

    3) On emulator i can open twitter.com web site , so internet is working

    Please help i need immediatly.

    Reply
    • lorenz says

      November 12, 2011 at 5:30 pm

      Hi, take a look at this discussion:

      http://stackoverflow.com/questions/6129316/twitter4j-android-authentication-challenge-is-null-exception

      Reply
  70. Shreyash says

    November 10, 2011 at 8:03 pm

    In My application i want to use to tweet the image with the text. So what more i have to do with your code ?

    Reply
    • lorenz says

      November 12, 2011 at 5:32 pm

      Hi, check out this post:

      http://www.londatiga.net/it/how-to-send-image-to-twitpic-from-android/

      Reply
  71. Amanda says

    November 14, 2011 at 3:27 pm

    Hi lorenz,

    Ive tried your application but it is unable to connect to twitter and it prompts “twitter connection fail”.

    Please advice.

    Thank you!

    Reply
    • lorenz says

      November 14, 2011 at 3:36 pm

      Try to use api.twitter.com instead of twitter.com for oauth url.

      In TwitterApp.java, the url should be like this;

      mHttpOauthprovider = new DefaultOAuthProvider(“http://api.twitter.com/oauth/request_token”,
      “http://api.twitter.com/oauth/access_token”,
      “http://api.twitter.com/oauth/authorize”);

      Reply
      • Amanda says

        November 16, 2011 at 3:43 pm

        Hi,

        Ive changed to api.twitter.com for the oauth url but i still cant connect to twitter.

        Thanks.

        Reply
        • lorenz says

          November 22, 2011 at 11:20 pm

          Have u set the callaback url on twitter app web settings?

          Reply
  72. Jeff Jolley says

    November 15, 2011 at 5:50 am

    Hi lorenz. Thanks for the great work. I do all of this (I’ve downloaded your zip file and altered it slightly for my consumer key and secret key, but I can’t get the web view to return to the app. It just goes to the callback URL. I use the callback url http://redir.domain.com (domain is actually replaced with my client’s domain name). My web host sends .domain.com to http://www.domain.com, so the webview just shows the http://www.domain.com page.

    Reply
    • Jeff Jolley says

      November 20, 2011 at 7:07 am

      I hope these screenshots help to explain the situation I’m up against.

      #1:
      http://www.fountaindew.com/screenshot1.png

      When I run the sample code in the zip file, I get an authorization screen from Twitter in a WebView

      #2:
      http://www.fountaindew.com/screenshot2.png

      When I select to authorize, it says it’s “redirecting you back to the application…”, but it never goes back to the application.

      #3:
      http://www.fountaindew.com/screenshot3.png

      Instead, the WebView shows the home page that the redirect URL eventually goes to. The WebView never goes away, and I never get a token to store in the preferences of the app.

      Reply
    • lorenz says

      November 22, 2011 at 10:47 pm

      Hi Jeff,

      It should return to app. The callback url has no effect on mobile app, it only works for web app. Where did u run the app? what version of android?

      Reply
  73. Ahariss says

    November 16, 2011 at 12:55 am

    hello, i am getting this error when i click connect button,knowing that i set the consumer key and consumer secret key below this is my log file when i pressed connect button:

    11-15 19:51:47.200: D/TwitterApp(401): Failed to get request token
    11-15 19:51:47.240: W/System.err(401): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://api.twitter.com/oauth/request_token
    11-15 19:51:47.240: W/System.err(401): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    11-15 19:51:47.240: W/System.err(401): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    11-15 19:51:47.240: W/System.err(401): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:121)
    11-15 19:51:47.240: W/System.err(401): Caused by: java.io.FileNotFoundException: http://api.twitter.com/oauth/request_token
    11-15 19:51:47.280: W/System.err(401): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:519)
    11-15 19:51:47.280: W/System.err(401): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    11-15 19:51:47.280: W/System.err(401): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    11-15 19:51:47.311: W/System.err(401): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    11-15 19:51:47.311: W/System.err(401): … 2 more
    11-15 19:51:47.461: W/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4066a188
    11-15 19:51:51.850: D/dalvikvm(141): GC_EXPLICIT freed 116K, 50% free 2999K/5895K, external 4787K/5329K, paused 79ms
    11-15 19:51:57.020: D/dalvikvm(241): GC_EXPLICIT freed 7K, 54% free 2543K/5511K, external 1625K/2137K, paused 178ms
    11-15 19:52:05.221: D/dalvikvm(271): GC_EXPLICIT freed 502K, 55% free 2595K/5703K, external 1625K/2137K, paused 97ms
    11-15 19:52:10.330: D/dalvikvm(317): GC_EXPLICIT freed 728K, 53% free 3105K/6471K, external 1625K/2137K, paused 184ms
    11-15 19:52:15.260: D/dalvikvm(365): GC_EXPLICIT freed 325K, 54% free 2538K/5511K, external 1625K/2137K, paused 104ms

    Any Luck for help please :)? this is exactly what i need for my app.

    Reply
    • lorenz says

      November 22, 2011 at 11:12 pm

      Have u set the callback url on twitter web settings page?

      Reply
  74. An=kur says

    November 16, 2011 at 5:58 am

    Hi lorenz

    Great tutorial. I am a noob to android api and eclipse and stuff, I am facing a problem. I downloaded the jar files that you said, added them to my project. I had created a new project by the name flixtermovie. Now to create the classes TestConnection.java, I right click the src folder of my project flixtermovie and click add class and ype in the name, after that I copy pasted your code.
    The problem is, there are lots of errors, most of them being “cannot be resolved to type” for various things like Activity, TwitterApp,CheckBox and so on,. Im guessing my libraries are not called properly, how do i solve this issue and get your code working on my computer? Please help me out, thanks a lot.

    Regards

    Reply
    • lorenz says

      November 22, 2011 at 11:16 pm

      I think you forget to import the required class first (Activity,Checkbox etc)..

      Reply
  75. Ankur says

    November 16, 2011 at 6:08 am

    Can I please have the code to helper classes? Thanks again

    Reply
    • lorenz says

      November 22, 2011 at 11:17 pm

      What do you mean helper classes? all codes are available on github as referenced in my tutorial.

      Reply
  76. sahil says

    November 23, 2011 at 11:47 am

    can tell me import files because it can not declare
    private TwitterApp mTwitter;

    Reply
  77. Ian Morgan says

    November 24, 2011 at 6:17 pm

    Hi lorenz,

    One thing I noticed is once I logged out, next it will not lead me to login page at all. Why it so? Pls reply me.

    Reply
    • lorenz says

      November 28, 2011 at 10:09 pm

      Hi Ian, the problem was fixed in the latest version on github. Try to download the source code from github.

      Reply
      • Dave Wagler says

        November 28, 2011 at 11:32 pm

        Hey Lorenz,

        It seems that even with that fix implemented in October for some reason the second log-in is showing a blank WebView. The first time the user logs in, the Redirecting URL receives an oauth verifier as a parameter, where as the second time the Redirecting URL only contains the oauth token.

        Any help is appreciated. Thanks for the great tutorial.

        Reply
        • lorenz says

          November 29, 2011 at 12:09 am

          Hi Dave,thanks for your info. I’ve tested on nexus s with GB and froyo on emulator they works fine. I’ll try to test it again and find the bug.

          Reply
        • Dave Wagler says

          November 29, 2011 at 12:14 am

          I believe I actually fixed it. The problem seemed that the web view still considered me logged in even if I reset my preferences/token. In the shouldOverrideUrlLoading method in the TwitterDialog class it was always returning true even if my URL did not start with the CallBack URL. With this in mind I changed the line:

          else if (url.startsWith(“authorize”)) {
          return false;
          }

          to

          } else if (url.contains(“authorize”)) {
          return false;
          }

          and it seems to have fixed my problem. I don’t think this will cause other issues but now when the user wants to log out they are technically signed into the browser they just need to sign out of it as well or just re-authorize the application if they wish.

          Reply
          • Dave Wagler says

            November 29, 2011 at 12:16 am

            If it helps, I have been testing on a Samsung Galaxy S running Android 2.3.3.

          • lorenz says

            November 29, 2011 at 12:25 am

            ok thank you Dave..

          • lorenz says

            November 29, 2011 at 12:25 am

            Ok i see, the problem is on webview. thank you for the solution, i have to test it again and make sure it will not cause other issues.

  78. Ian Morgan says

    November 24, 2011 at 6:21 pm

    Hi lorenz,

    One thing I noticed, After Logging out, next time Iam not leding to login page at all. Why It is So? Pls Reply me.

    Reply
  79. Willy says

    November 27, 2011 at 4:07 pm

    Hi lorenz,

    I’ve got an error while connect to twitter from android emulator
    I used AVD 2.1 and have change

    mHttpOauthprovider = new DefaultOAuthProvider(
    “https://api.twitter.com/oauth/request_token”, “https://api.twitter.com/oauth/access_token”,
    “https://api.twitter.com/oauth/authorize”);

    fill the consumer and secret key but I still got error like this:

    LogCat:

    11-27 15:59:26.888: DEBUG/TwitterApp(461): Failed to get request token
    11-27 15:59:26.918: WARN/System.err(461): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Host is unresolved: api.twitter.com:443
    11-27 15:59:26.927: WARN/System.err(461): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    11-27 15:59:26.988: WARN/System.err(461): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    11-27 15:59:27.017: WARN/System.err(461): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    11-27 15:59:27.017: WARN/System.err(461): Caused by: java.net.UnknownHostException: Host is unresolved: api.twitter.com:443
    11-27 15:59:27.048: WARN/System.err(461): at java.net.Socket.connect(Socket.java:1037)
    11-27 15:59:27.077: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:62)
    11-27 15:59:27.088: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
    11-27 15:59:27.117: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
    11-27 15:59:27.127: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
    11-27 15:59:27.148: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
    11-27 15:59:27.180: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:395)
    11-27 15:59:27.188: WARN/System.err(461): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.connect(HttpsURLConnection.java:146)
    11-27 15:59:27.207: WARN/System.err(461): at oauth.signpost.basic.DefaultOAuthProvider.sendRequest(DefaultOAuthProvider.java:48)
    11-27 15:59:27.207: WARN/System.err(461): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)
    11-27 15:59:27.207: WARN/System.err(461): … 2 more
    11-27 15:59:27.278: INFO/NotificationService(58): enqueueToast pkg=net.londatiga.android callback=android.app.ITransientNotification$Stub$Proxy@43e189d8 duration=1
    11-27 15:59:27.498: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43cda4b8

    Reply
    • Willy says

      November 27, 2011 at 4:45 pm

      Hi Lorenz,
      I have solved the problem, but when I post to twitter, the emulator said that it is failed

      LogCat:
      11-27 16:40:30.208: INFO/NotificationService(63): enqueueToast pkg=net.londatiga.android callback=android.app.ITransientNotification$Stub$Proxy@44c558e8 duration=0
      11-27 16:40:31.789: INFO/global(313): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
      11-27 16:40:31.809: INFO/NotificationService(63): enqueueToast pkg=net.londatiga.android callback=android.app.ITransientNotification$Stub$Proxy@44c3a178 duration=0

      Reply
    • lorenz says

      November 28, 2011 at 10:28 pm

      Make sure you don’t have problem with internet connection on emulator

      Reply
  80. Dawid says

    December 1, 2011 at 5:10 pm

    I am getting blank page in autorization.

    http://imageshack.us/f/834/device20111201110552.png/

    Reply
    • lorenz says

      December 2, 2011 at 9:44 pm

      Could you give me the error log messages?

      Reply
  81. Tweets says

    December 12, 2011 at 5:26 pm

    New to integration of twitter.

    Could you provide link for downloading sample project also

    Reply
  82. Eddy Faustor says

    December 18, 2011 at 7:24 am

    I really thank you, because you helped me a lot!!

    Reply
  83. yogi says

    January 10, 2012 at 9:01 pm

    hi,

    An getting an error in Log cat has : “unauthorized access 401 error”.

    Can u plz give me the solution for this.

    Thanks & Br,
    Yogi

    Reply
  84. TheTime says

    January 11, 2012 at 7:08 pm

    To get this working :

    * set the callback url on twitter web settings page to :
    https://dev.twitter.com/app

    * change this :

    mHttpOauthprovider = new DefaultOAuthProvider(”http://twitter.com/oauth/request_token”,
    “http://twitter.com/oauth/access_token”,
    “http://twitter.com/oauth/authorize”);

    to this :

    mHttpOauthprovider = new DefaultOAuthProvider(”http://api.twitter.com/oauth/request_token”,
    “http://api.twitter.com/oauth/access_token”,
    “http://api.twitter.com/oauth/authorize”);

    Reply
  85. Addy says

    January 17, 2012 at 3:42 am

    Hi Lorenz,

    Thanks for this twitter app code, I am getting through all the authorisation bits fine but for some reason I cannot post to twitter, log cat gives me the following error.

    01-16 20:21:02.776: D/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol

    Hope you can help.

    Cheers

    Addy

    Reply
  86. Tariq says

    January 24, 2012 at 5:31 am

    In the first I really thank you for this amazing code. I have problem: when I login in the first time everything work correctly and succeed in login, but if I logout and login again, the dialog become clean as follow:
    http://imageshack.us/photo/my-images/841/sc20120124012121.jpg/

    I used your last code updated, please help.

    Reply
  87. dinu says

    January 24, 2012 at 5:18 pm

    for the first time i can able to login, when i try to post tweet app show post to twitter failed. pls give me some suggestion

    Reply
  88. dinu says

    January 24, 2012 at 6:05 pm

    hi lorenz,

    I got fixed one issue related to posting the tweet. The reason for twitter posting failed is due to app registration in dev.twitter.com which is in read only mode. I updated it to read and write mode which cleared the problem.It worked for me if it is not relevant pls ignore.

    Reply
  89. Punit says

    February 6, 2012 at 2:25 pm

    Hi lorenz

    nice to see u again , i am facing problem, i dont want the pin each & every time user login, & previously it was possible to share from twitter but now i cant share from twitter..
    pls help me

    check the issue on same app as fb if u remember
    https://market.android.com/details?id=com.irobotz.quote

    Reply
  90. MAC says

    February 6, 2012 at 6:56 pm

    Post to Twitter failed

    02-06 17:04:57.402: I/System.out(1214): {“error”:”Invalid \/ expired Token”,”request”:”\/1\/statuses\/update.json”}

    I have login successfully but not able to update status

    Reply
  91. MAC says

    February 6, 2012 at 6:58 pm

    message :Post to Twitter failed

    02-06 17:04:57.402: I/System.out(1214): {“error”:”Invalid \/ expired Token”,”request”:”\/1\/statuses\/update.json”}

    401:Authentication credentials were missing or incorrect.

    Reply
  92. Tjay says

    March 8, 2012 at 4:04 pm

    Great post. Was able to post to twitter after a few glitches.

    Reply
  93. Tjay says

    March 8, 2012 at 4:05 pm

    Great Post. Was able to use this code on my Android app.

    Reply
  94. Rooban Ponraj says

    April 4, 2012 at 1:13 pm

    I am getting this error in TwitterApp constructor.

    04-04 11:40:05.478: E/AndroidRuntime(558): FATAL EXCEPTION: main
    04-04 11:40:05.478: E/AndroidRuntime(558): java.lang.VerifyError: net.londatiga.android.TwitterApp
    04-04 11:40:05.478: E/AndroidRuntime(558): at net.londatiga.android.TestConnect.onCreate(TestConnect.java:54)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.os.Looper.loop(Looper.java:123)
    04-04 11:40:05.478: E/AndroidRuntime(558): at android.app.ActivityThread.main(ActivityThread.java:4627)
    04-04 11:40:05.478: E/AndroidRuntime(558): at java.lang.reflect.Method.invokeNative(Native Method)
    04-04 11:40:05.478: E/AndroidRuntime(558): at java.lang.reflect.Method.invoke(Method.java:521)
    04-04 11:40:05.478: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    04-04 11:40:05.478: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    04-04 11:40:05.478: E/AndroidRuntime(558): at dalvik.system.NativeStart.main(Native Method)

    Reply
  95. Amit Tiwari says

    April 12, 2012 at 9:57 pm

    Hi lorenz.

    I can login in twitter but my comments are not showing in twitter.I am using android2.1 and I have change the twitter.com to api.twitter.com.But still I am facing the problem.Please help me.

    Thanks

    Reply
  96. Amit Tiwari says

    April 12, 2012 at 10:00 pm

    Hi Lorenz

    I am using your code .I can login into twitter but I can not see my message into my twitter account.I am using android 2.1 and I have changed the url from twitter.com to api.twitter.com but still I am facing the issue.Please help!

    Thanks

    Reply
  97. Rommy says

    April 26, 2012 at 5:56 pm

    I downloaded the code and tried it exactly with no changes (except twitter consume key and secret key).
    But, after I ran it, it always bring force close.

    Here’s the logcat:

    04-26 17:33:49.416: E/AndroidRuntime(895): FATAL EXCEPTION: main
    04-26 17:33:49.416: E/AndroidRuntime(895): java.lang.VerifyError: net.londatiga.android.TwitterApp
    04-26 17:33:49.416: E/AndroidRuntime(895): at net.londatiga.android.TestConnect.onCreate(TestConnect.java:52)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.os.Looper.loop(Looper.java:123)
    04-26 17:33:49.416: E/AndroidRuntime(895): at android.app.ActivityThread.main(ActivityThread.java:4627)
    04-26 17:33:49.416: E/AndroidRuntime(895): at java.lang.reflect.Method.invokeNative(Native Method)
    04-26 17:33:49.416: E/AndroidRuntime(895): at java.lang.reflect.Method.invoke(Method.java:521)
    04-26 17:33:49.416: E/AndroidRuntime(895): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    04-26 17:33:49.416: E/AndroidRuntime(895): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    04-26 17:33:49.416: E/AndroidRuntime(895): at dalvik.system.NativeStart.main(Native Method)

    Any solution for my problem???

    Reply
  98. MIP TECH says

    April 30, 2012 at 7:59 pm

    i download the code and try but is show error i change only key and secretkey other is same but is show me error
    i am already added jar file from your folder

    is show me error twitter4j.TwitterFactory class not found

    04-30 17:47:32.825: E/dalvikvm(247): Could not find class ‘twitter4j.TwitterFactory’, referenced from method net.londatiga.android.TwitterApp.
    04-30 17:47:32.835: W/dalvikvm(247): VFY: unable to resolve new-instance 96 (Ltwitter4j/TwitterFactory;) in Lnet/londatiga/android/TwitterApp;
    04-30 17:47:32.835: D/dalvikvm(247): VFY: replacing opcode 0x22 at 0x000c
    04-30 17:47:32.835: D/dalvikvm(247): Making a copy of Lnet/londatiga/android/TwitterApp;. code (184 bytes)
    04-30 17:47:32.835: W/dalvikvm(247): VFY: unable to find class referenced in signature (Ltwitter4j/http/AccessToken;)
    04-30 17:47:32.835: W/dalvikvm(247): VFY: unable to find class referenced in signature (Loauth/signpost/OAuthProvider;)
    04-30 17:47:32.846: W/dalvikvm(247): VFY: unable to find class referenced in signature (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;)
    04-30 17:47:32.855: W/dalvikvm(247): VFY: unable to find class referenced in signature (Ltwitter4j/http/AccessToken;)
    04-30 17:47:32.855: W/dalvikvm(247): VFY: unable to find class referenced in signature (Ltwitter4j/Twitter;)
    04-30 17:47:32.855: I/dalvikvm(247): Could not find method twitter4j.Twitter.setOAuthConsumer, referenced from method net.londatiga.android.TwitterApp.configureToken
    04-30 17:47:32.855: W/dalvikvm(247): VFY: unable to resolve virtual method 210: Ltwitter4j/Twitter;.setOAuthConsumer (Ljava/lang/String;Ljava/lang/String;)V
    04-30 17:47:32.865: D/dalvikvm(247): VFY: replacing opcode 0x6e at 0x000a
    04-30 17:47:32.865: D/dalvikvm(247): Making a copy of Lnet/londatiga/android/TwitterApp;.configureToken code (60 bytes)
    04-30 17:47:32.875: I/dalvikvm(247): Could not find method twitter4j.Twitter.updateStatus, referenced from method net.londatiga.android.TwitterApp.updateStatus
    04-30 17:47:32.875: W/dalvikvm(247): VFY: unable to resolve virtual method 211: Ltwitter4j/Twitter;.updateStatus (Ljava/lang/String;)Ltwitter4j/Status;
    04-30 17:47:32.875: D/dalvikvm(247): VFY: replacing opcode 0x6e at 0x0002
    04-30 17:47:32.875: D/dalvikvm(247): Making a copy of Lnet/londatiga/android/TwitterApp;.updateStatus code (44 bytes)
    04-30 17:47:32.875: W/dalvikvm(247): VFY: unable to resolve exception class 95 (Ltwitter4j/TwitterException;)
    04-30 17:47:32.875: W/dalvikvm(247): VFY: unable to find exception handler at addr 0x6
    04-30 17:47:32.875: W/dalvikvm(247): VFY: rejected Lnet/londatiga/android/TwitterApp;.updateStatus (Ljava/lang/String;)V
    04-30 17:47:32.875: W/dalvikvm(247): VFY: rejecting opcode 0x0d at 0x0006
    04-30 17:47:32.875: W/dalvikvm(247): VFY: rejected Lnet/londatiga/android/TwitterApp;.updateStatus (Ljava/lang/String;)V
    04-30 17:47:32.875: W/dalvikvm(247): Verifier rejected class Lnet/londatiga/android/TwitterApp;
    04-30 17:47:32.875: D/AndroidRuntime(247): Shutting down VM
    04-30 17:47:32.875: W/dalvikvm(247): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
    04-30 17:47:32.885: E/AndroidRuntime(247): Uncaught handler: thread main exiting due to uncaught exception
    04-30 17:47:32.885: E/AndroidRuntime(247): java.lang.VerifyError: net.londatiga.android.TwitterApp
    04-30 17:47:32.885: E/AndroidRuntime(247): at net.londatiga.android.TestConnect.onCreate(TestConnect.java:52)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.os.Looper.loop(Looper.java:123)
    04-30 17:47:32.885: E/AndroidRuntime(247): at android.app.ActivityThread.main(ActivityThread.java:4363)
    04-30 17:47:32.885: E/AndroidRuntime(247): at java.lang.reflect.Method.invokeNative(Native Method)
    04-30 17:47:32.885: E/AndroidRuntime(247): at java.lang.reflect.Method.invoke(Method.java:521)
    04-30 17:47:32.885: E/AndroidRuntime(247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    04-30 17:47:32.885: E/AndroidRuntime(247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    04-30 17:47:32.885: E/AndroidRuntime(247): at dalvik.system.NativeStart.main(Native Method)
    04-30 17:47:32.905: I/dalvikvm(247): threadid=7: reacting to signal 3
    04-30 17:47:32.905: E/dalvikvm(247): Unable to open stack trace file ‘/data/anr/traces.txt’: Permission denied
    04-30 17:49:41.555: W/ActivityThread(270): Application net.londatiga.android is waiting for the debugger on port 8100…
    04-30 17:49:41.575: I/System.out(270): Sending WAIT chunk
    04-30 17:49:41.644: I/dalvikvm(270): Debugger is active
    04-30 17:49:41.785: I/System.out(270): Debugger has connected
    04-30 17:49:41.785: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:41.985: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:42.246: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:42.455: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:42.655: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:42.858: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:43.129: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:43.347: I/System.out(270): waiting for debugger to settle…
    04-30 17:49:43.619: I/System.out(270): debugger has settled (1364)
    04-30 17:49:44.035: E/dalvikvm(270): Could not find class ‘twitter4j.TwitterFactory’, referenced from method net.londatiga.android.TwitterApp.
    04-30 17:49:44.035: W/dalvikvm(270): VFY: unable to resolve new-instance 96 (Ltwitter4j/TwitterFactory;) in Lnet/londatiga/android/TwitterApp;
    04-30 17:49:44.035: D/dalvikvm(270): VFY: replacing opcode 0x22 at 0x000c
    04-30 17:49:44.035: D/dalvikvm(270): Making a copy of Lnet/londatiga/android/TwitterApp;. code (184 bytes)
    04-30 17:49:44.045: W/dalvikvm(270): VFY: unable to find class referenced in signature (Ltwitter4j/http/AccessToken;)
    04-30 17:49:44.055: W/dalvikvm(270): VFY: unable to find class referenced in signature (Loauth/signpost/OAuthProvider;)
    04-30 17:49:44.065: W/dalvikvm(270): VFY: unable to find class referenced in signature (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;)
    04-30 17:49:44.075: W/dalvikvm(270): VFY: unable to find class referenced in signature (Ltwitter4j/http/AccessToken;)
    04-30 17:49:44.085: W/dalvikvm(270): VFY: unable to find class referenced in signature (Ltwitter4j/Twitter;)
    04-30 17:49:44.095: I/dalvikvm(270): Could not find method twitter4j.Twitter.setOAuthConsumer, referenced from method net.londatiga.android.TwitterApp.configureToken
    04-30 17:49:44.095: W/dalvikvm(270): VFY: unable to resolve virtual method 210: Ltwitter4j/Twitter;.setOAuthConsumer (Ljava/lang/String;Ljava/lang/String;)V
    04-30 17:49:44.095: D/dalvikvm(270): VFY: replacing opcode 0x6e at 0x000a
    04-30 17:49:44.095: D/dalvikvm(270): Making a copy of Lnet/londatiga/android/TwitterApp;.configureToken code (60 bytes)
    04-30 17:49:44.145: I/dalvikvm(270): Could not find method twitter4j.Twitter.updateStatus, referenced from method net.londatiga.android.TwitterApp.updateStatus
    04-30 17:49:44.145: W/dalvikvm(270): VFY: unable to resolve virtual method 211: Ltwitter4j/Twitter;.updateStatus (Ljava/lang/String;)Ltwitter4j/Status;
    04-30 17:49:44.145: D/dalvikvm(270): VFY: replacing opcode 0x6e at 0x0002
    04-30 17:49:44.145: D/dalvikvm(270): Making a copy of Lnet/londatiga/android/TwitterApp;.updateStatus code (44 bytes)
    04-30 17:49:44.155: W/dalvikvm(270): VFY: unable to resolve exception class 95 (Ltwitter4j/TwitterException;)
    04-30 17:49:44.155: W/dalvikvm(270): VFY: unable to find exception handler at addr 0x6
    04-30 17:49:44.155: W/dalvikvm(270): VFY: rejected Lnet/londatiga/android/TwitterApp;.updateStatus (Ljava/lang/String;)V
    04-30 17:49:44.155: W/dalvikvm(270): VFY: rejecting opcode 0x0d at 0x0006
    04-30 17:49:44.155: W/dalvikvm(270): VFY: rejected Lnet/londatiga/android/TwitterApp;.updateStatus (Ljava/lang/String;)V
    04-30 17:49:44.155: W/dalvikvm(270): Verifier rejected class Lnet/londatiga/android/TwitterApp;
    04-30 17:51:07.896: W/jdwp(270): Debugger is telling the VM to exit with code=1
    04-30 17:51:07.896: I/dalvikvm(270): GC lifetime allocation: 2511 bytes

    Reply
  99. ramesh says

    May 5, 2012 at 5:30 pm

    hi lorenz, i need to implement the twitter posting but not only text but images also can you suggest some post for that also.

    Reply
  100. Sathya chandran says

    May 8, 2012 at 12:43 pm

    Hi Lorenze,

    Thanks for the post. It helped me a lot.

    Reply
  101. ganesh says

    May 9, 2012 at 11:48 pm

    hey lorenz..

    this help me a lot thx for posting.. authentication is working proparly..but when i posting any text..its saying post failed plz help me….

    Reply
    • Dayanand says

      July 20, 2012 at 8:30 pm

      Set your application permission in twitter web site.

      Reply
  102. ganesh says

    May 10, 2012 at 2:54 pm

    hey Lorenze

    thax for posting this artical, it help me lot..I am using your code .I can login into twitter but whenver im posting any tweet it saying tweet post is failed plz help..I am using android 2.2 google API

    Reply
    • sri says

      May 31, 2012 at 6:58 pm

      ganesh i cant even run the prog some fatal expression is showing up can u help me with that

      Reply
      • ganesh says

        June 28, 2012 at 7:49 pm

        check the jar files in project

        Reply
    • John Nogueira says

      June 3, 2012 at 10:15 am

      Are you getting error code 403 (with duplicate message error)? If your app is sending the same message as in a previous post, try changing the message.

      Reply
  103. Swathi says

    May 25, 2012 at 4:39 pm

    can some one post the full code of this?

    Reply
  104. Swathi says

    May 25, 2012 at 4:40 pm

    can some one post full code of this?

    Reply
    • tarun says

      July 16, 2012 at 1:07 am

      https://github.com/lorensiuswlt/AndroidTwitter

      Reply
  105. sri says

    May 31, 2012 at 6:56 pm

    hey lorenze

    some fatal expression is showing up and i cant figure it out can u help me with that

    Reply
  106. John Nogueira says

    June 3, 2012 at 10:09 am

    Just in case anyone wanted to know how to clear the user’s credentials from the Twitter webview… (In addition to clearing the access token from the app’s shared preferences, this modification forces the user to re-enter their username and password on the Twitter webview when signing back-on).

    1. In twitterapp.java, replace resetAccessToken function with this:

    public void resetAccessToken(Context context) {
    if (mAccessToken != null) {
    mSession.resetAccessToken();

    //clear webview cookies (in case user saved credentials on Twitter webview)
    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    mAccessToken = null;
    }
    }

    2. From main activity, call:

    mTwitter.resetAccessToken(this);

    Reply
    • krishna kanth says

      June 19, 2012 at 12:28 pm

      THANK U VERY MUCH FOR YOUR POST … i AM TRYING TO RELOGIN INTO TWIITTER FROM 6 MONTHS ………… BUT WHOMEVER I ASK THEY JUST SAY ONE SIMPLE THING IN TWITTER THERE IS SINGLE SIGN IN ON SO U CANNOT RELOGIN AGAIN AND ALSO ONCE YOU HAVE LOGGED IN YOU CANNOT LOGOUT. But u proved that they are wrong and thank u very very much for your post… It helped a department in a very big way … thank u very much … 🙂

      Reply
  107. Upendra says

    June 5, 2012 at 12:16 pm

    I got Exception here…

    mTwitter = new TwitterApp(this, twitter_consumer_key,twitter_secret_key);

    The Exception is::::

    E/AndroidRuntime(318): java.lang.VerifyError: net.londatiga.android.TwitterApp

    Reply
  108. ganesh says

    June 13, 2012 at 7:40 pm

    hey lorenze,

    how to post image with tweet using twitter API without using twitpic. if u hav any demo or sample code then post me the link

    thnk you in advance

    Reply
  109. krishna kanth says

    June 19, 2012 at 12:05 pm

    Hello lorenze, thanks for your post. I am able to connect to twitter and post successfully. But when i deleted the connection and try to connect again it is not working. It is showing a blank white page and also it is not calling the onError method in TwDialogListener. Please tell me where it was going wrong?

    Reply
  110. fjr619 says

    July 12, 2012 at 2:50 pm

    i wanna ask something. i can connect to twitter. but when i logout and i want to login again, it just stuck in white page. so what must i do for fix that problem?i really need this app for study about twitter connection.thanks

    Reply
  111. tarun says

    July 16, 2012 at 1:06 am

    thanks for this twitter example.. this is the only working example I found on google…

    Reply
  112. André says

    July 19, 2012 at 5:30 pm

    Thank you very much. How can I post a tweet without display/activity screen? Thanks

    Reply
  113. Vijay says

    July 24, 2012 at 4:49 pm

    When i am click on Submit it will display a Toast :: Review Post then after sometime another Toast display “Post To Twitter Failed.”.

    please Solve it…. please…. please….

    Reply
    • lorenz says

      July 30, 2012 at 10:01 pm

      Could you give me the log cat error message for more detail?

      Reply
  114. Mohamed ismail says

    July 26, 2012 at 12:20 pm

    its very useful above code,work fine
    Thanks

    Reply
  115. Can says

    July 26, 2012 at 3:55 pm

    Hi, I need a help about that codes.

    I downloaded your project. It’s working properly. But I wanted to build my own app. I imported the jar files. There is no problem. Then I take your TwitterApp.java file, TwitterDialog.java file and TwitterSession.java files to my package. I’m trying to login to twitter when I click on a button. When I create the instance of TwitterApp I got a problem. It gives me error on this code;

    mTwitter = new TwitterApp(getApplicationContext(), twitter_consumer_key,
    twitter_secret_key);

    and then crashes the application.

    I couldn’t figure it out

    Reply
    • lorenz says

      July 30, 2012 at 10:00 pm

      Hi,

      Could you give the log cat error message for more detail?

      Reply
  116. asp17 says

    July 30, 2012 at 3:26 pm

    hi,

    I downloaded your project. It gives me error on this code;

    mTwitter = new TwitterApp(getApplicationContext(), twitter_consumer_key,twitter_secret_key);

    and then crashes the application.

    plz help me.

    Reply
    • lorenz says

      July 30, 2012 at 9:56 pm

      Hi,

      Could you give me the log cat error message?

      Reply
  117. Rubyd says

    July 31, 2012 at 12:11 pm

    I downloaded this code. But it gives me Error …. :'(

    mTwitter = new TwitterApp(this, twitter_consumer_key,twitter_secret_key);The Exception is::::
    java.lang.VerifyError: net.londatiga.android.TwitterApp

    ———————————–
    Pls solve this,

    Reply
    • Ramesh Annadurai says

      August 2, 2012 at 2:38 pm

      Hi Rubyd,

      1) Remove the libraries from the standard Java build path :

      Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the “Android X.X” (2.3.3 in my case) and the “Android Dependencies”

      2) Copy the jar files into libs folder :

      a. Create “libs” folder in your project directory without double quotes.

      b. Copy all the required jar files and paste in libs folder.

      c. clean the project.

      By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project

      Thanks,
      RAMESH ANNADURAI

      Reply
      • lorenz says

        August 6, 2012 at 12:25 am

        Hi Ramesh, thanks for that trick..thats the right way to solve the problem. 😉

        Reply
        • Talal Qaboos says

          June 3, 2013 at 8:25 pm

          i have same problem that RubyD have.. i have also try the way Ramesh told to make a libs folder and paste all jar packages into it. but error is same on mTwitter on create(Bundle). in TestConnect class.. my logs are
          06-03 19:18:12.774: E/AndroidRuntime(18667): FATAL EXCEPTION: main
          06-03 19:18:12.774: E/AndroidRuntime(18667): java.lang.VerifyError: net.londatiga.android.TwitterApp
          06-03 19:18:12.774: E/AndroidRuntime(18667): at net.londatiga.android.TestConnect.onCreate(TestConnect.java:52)
          06-03 19:18:12.774: E/AndroidRuntime(18667): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)

          please help me pleaseeeeeeee 🙁 :'(

          Reply
  118. joseph says

    August 14, 2012 at 5:10 pm

    Hi,

    I downloaded your application and just modified the twitter_consumer_key and twitter_secret_key and set it to my app key. Im using android 2.3.3. Looks like its not working perfectly.

    The problem is the app unable to connect to twitter.

    This are the logs:

    08-14 18:02:46.613: D/TwitterApp(3830): Failed to get request token
    08-14 18:02:46.613: W/System.err(3830): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://twitter.com/oauth/request_token
    08-14 18:02:46.613: W/System.err(3830): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    08-14 18:02:46.613: W/System.err(3830): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    08-14 18:02:46.613: W/System.err(3830): at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
    08-14 18:02:46.613: W/System.err(3830): Caused by: java.io.FileNotFoundException: http://twitter.com/oauth/request_token
    08-14 18:02:46.613: W/System.err(3830): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
    08-14 18:02:46.613: W/System.err(3830): at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    08-14 18:02:46.623: W/System.err(3830): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    08-14 18:02:46.623: W/System.err(3830): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    08-14 18:02:46.623: W/System.err(3830): … 2 more

    Any sugestion and comments are very much appreciated.
    Thanks in advance.

    Reply
    • lorenz says

      August 20, 2012 at 11:23 pm

      Hi joseph, try to use https instead of http when accessing request token

      https://twitter.com/oauth/request_token

      Reply
      • joseph says

        August 28, 2012 at 1:04 pm

        I tried to update it but no luck.
        Still it doesnt work. Thanks anyway

        Reply
  119. Yahya says

    August 29, 2012 at 9:58 pm

    I’ve set:

    REQUEST_TOKEN = “https://api.twitter.com/oauth/request_token”;
    ACCESS_TOKEN = “https://api.twitter.com/oauth/access_token”;
    AUTHORIZE = “https://api.twitter.com/oauth/authorize”;

    and now it works… But i have a problem with CALLBACK_URL… I’ve set it to None when i create twitter app and now it’s not returning token to app, just require user to get pin code into app, and stuck there… What should i do? How should the CALLBACK_URL be?

    Thanks in advance…

    Reply
  120. Boon says

    August 30, 2012 at 2:40 pm

    hi,i get this when i postToTwitter :-

    TwitterException{exceptionCode=[15bb6564-00e4d61f], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a855f3e889507)}

    Reply
  121. Murali says

    August 30, 2012 at 5:59 pm

    Hi,

    When i logout to current user and try to login to another user am getting login filed.Am also clearing cookiemanager.am getting following errors.

    08-30 16:20:04.344: W/System.err(1846): java.lang.IllegalStateException: consumer key/secret pair already set.
    08-30 16:20:04.344: W/System.err(1846): at twitter4j.TwitterOAuthSupportBaseImpl.setOAuthConsumer(TwitterOAuthSupportBaseImpl.java:234)
    08-30 16:20:04.344: W/System.err(1846): at twitter4j.Twitter.setOAuthConsumer(Twitter.java:54)
    08-30 16:20:04.353: W/System.err(1846): at net.londatiga.android.TwitterApp.configureToken(TwitterApp.java:78)
    08-30 16:20:04.353: W/System.err(1846): at net.londatiga.android.TwitterApp.access$7(TwitterApp.java:76)
    08-30 16:20:04.353: W/System.err(1846): at net.londatiga.android.TwitterApp$3.run(TwitterApp.java:158)

    help me thanks in advance.

    Reply
    • Dejan says

      September 20, 2012 at 6:49 am

      I managed to make it work by re-initializing instance, like this..

      mTwitter.resetAccessToken(this);
      mTwitter = new TwitterApp(this, consumerKey,consumerSecret);
      mTwitter.setListener(mTwLoginDialogListener);
      mTwitter.authorize();

      not sure if this is the right way, but works for me 🙂

      Reply
  122. stephen says

    September 3, 2012 at 1:52 pm

    Hi Lorenz,
    I installed your app in my android galaxy y.version 2.3.3.every authorization is done perfectly .when i post a tweet.i m getting a toast that the tweet is posted..but when i check my twitter account..there is no tweet could u help me out

    Reply
  123. fjr619 says

    September 3, 2012 at 2:58 pm

    will you update your code when Twitter API upgrade to 1.1 ? because many change on new API

    Reply
    • stephen says

      September 4, 2012 at 12:13 am

      could u send me your email id..i ll post u my source code

      Reply
      • fjr619 says

        September 7, 2012 at 7:01 am

        here my email : frank.jr.619@gmail.com

        thanks for your help

        Reply
  124. stephen says

    September 4, 2012 at 6:40 pm

    i used the above code with the jar files attached to it…if i m to use the latest upgraded version of the above jar files i m getting error in the source code..so i used the jar files attached below..works fine.but not able to post on wall..got the toast saying the tweet has been posted..

    Reply
  125. Maykec says

    September 11, 2012 at 10:22 pm

    Would i please you for source code (api 1.1) to?

    tnx 🙂

    Reply
    • lorenz says

      September 11, 2012 at 10:47 pm

      Hi, i’ll update the code soon..;)

      Reply
  126. fjr619 says

    September 13, 2012 at 10:29 am

    i want ask with your code, will access token be expired although user has been login and not logout?and if yes, how to make access token again without login again.

    Reply
  127. Grayson says

    September 21, 2012 at 3:29 am

    Hi I’m having a problem connecting to twitter (program starts up in my eclipse emulator and when I click on “Twitter (not connected)” and it tries to connect it comes back with “Twitter Connection Failed”)(the emulator does have an internet connection). I’ve set the twitter_consumer_key and twitter_secret_key in both TestPost.java and TestConnect.java with my own. Other than that I have not changed or added anything else to the code (gotten from github).
    Is there anything else I need to set in the code to connect to Twitter. I would assume there would need to be some sort of username and password, though if it connects to twitter then I would assume Twitter would handle that instead of your code.

    Reply
  128. iiwak says

    September 21, 2012 at 2:48 pm

    – WARNING: Application does not specify an API level requirement!
    – Device API version is 10 (Android 2.3.7)

    What should I do?
    I use debuging usb connection.
    I debug your facebook connection code before. It work correctly. But I got error on your twitter connection code.
    Help me please.

    Reply
    • iiwak says

      September 21, 2012 at 3:48 pm

      I try to resolve my problem. I think “TwitterApp.java” not work correctly. I’ll got error when execute “TwitterApp.java”
      Help me, Lorenz.
      🙂

      Reply
  129. rushabh says

    October 8, 2012 at 9:08 pm

    I am getting “Twitter connection failed” error while executing this function:

    mTwitter.authorize();

    in simulator as well as in device i am getting this error. i have all config jar files and also keys.

    Reply
  130. ningning says

    October 11, 2012 at 4:06 pm

    Excuse me: how to release the twitter with image?For twitter API 1.1, your code is still valid?

    Reply
  131. rose says

    October 11, 2012 at 4:10 pm

    我英语不好,直接用汉语表达吧!在android app怎么发布带有图片的状态(推文)呢?

    Reply
  132. minal says

    October 15, 2012 at 7:08 pm

    private TwitterApp mTwitter;
    I got error on that…what can i do???

    Reply
  133. suresh k r says

    November 3, 2012 at 3:22 am

    I had done all the steps which stated above but wen i click connect it shows that twitter connection failed.. can anyone help me out wat mistake i had done…

    Reply
    • myq says

      November 30, 2012 at 6:57 pm

      Hello suresh,

      Did you get to manage work around of this issue please?

      Reply
  134. nita says

    November 11, 2012 at 12:23 am

    Someone help me please 🙁
    I’m very new to android, and still learning how to develop an android program.

    I did exactly these steps, but in the end my program is unexpectedly force closed.

    When I checked on the LogCat it show like this:

    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.os.Handler.dispatchMessage(Handler.java:99)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.os.Looper.loop(Looper.java:123)
    11-10 17:15:40.987: E/AndroidRuntime(463): at android.app.ActivityThread.main(ActivityThread.java:3683)
    11-10 17:15:40.987: E/AndroidRuntime(463): at java.lang.reflect.Method.invokeNative(Native Method)
    11-10 17:15:40.987: E/AndroidRuntime(463): at java.lang.reflect.Method.invoke(Method.java:507)
    11-10 17:15:40.987: E/AndroidRuntime(463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    11-10 17:15:40.987: E/AndroidRuntime(463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    11-10 17:15:40.987: E/AndroidRuntime(463): at dalvik.system.NativeStart.main(Native Method)

    Does anyone know what is the problem?

    Thanks before~

    Reply
  135. Emerald214 says

    February 4, 2013 at 9:30 am

    Could you give an update for Twitter API 1.1 and Twitter4J 3.0?

    Reply
  136. androidvideo says

    February 6, 2013 at 8:25 pm

    Wonderful blog! I found it while searching on Yahoo
    News. Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there! Cheers

    Reply
  137. Arun Jose says

    February 12, 2013 at 6:15 pm

    The app fails to log in!
    Toast showing: Twitter connection failed.
    Changed the keys, updated the links….
    what do you think?

    Reply
  138. Emerald214 says

    February 18, 2013 at 1:52 pm

    Coul you post an update for Twitter API 1.1? What must I do to migrate from 1.0 to 1.1?

    Reply
  139. venkat says

    February 26, 2013 at 2:04 pm

    thank you for your blog.I used your code and starting a am getting force close.This is the error displayed in logcat:java.lang.VerifyError: net.londatiga.android.TwitterApp.Please help me,I dont know why I am getting this error.

    Reply
  140. Felipe says

    March 17, 2013 at 8:00 pm

    Thanks, it’s working fine

    Reply
  141. Krish says

    April 2, 2013 at 2:05 pm

    hai i tried this code…i replaced my secret key and consumer key for this code..no errors but wen i run this in emulator always its giving twitter connection failed..i could not solve this problem…please solve this…thanks in advance..
    Lorenz…

    Reply
  142. Krish says

    April 2, 2013 at 3:47 pm

    Hey i made the auth urls as https://…its logged in..but during posting it says post failed..plz guide me…
    thanks in advance..

    Reply
  143. Krish says

    April 2, 2013 at 4:37 pm

    hey i solved it..i forgot to give secret key and consumer key in TestPost.java…
    But why we need again in in this java file…any way we authenticated in TestConnect.java file..
    Thanks Lorenz..

    Reply
  144. ynmly says

    April 3, 2013 at 7:07 pm

    thanks for yourr blog….i have tried both facebook and twitter..facebook one running excellent…but i am facing problem in twitter..it give an error of :-

    [2013-04-03 16:51:48 – Dex Loader] Unable to execute dex: Multiple dex files define Ltwitter4j/TwitterBase;
    [2013-04-03 16:51:48 – AndroidTwitter-master] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Ltwitter4j/TwitterBase;
    [2013-04-03 17:35:19 – Dex Loader] Unable to execute dex: Multiple dex files define Ltwitter4j/TwitterBase;
    [2013-04-03 17:35:19 – AndroidTwitter-master] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Ltwitter4j/TwitterBase;

    could you plz plz me
    thanks lorenz..

    Reply
  145. Krishnaveni says

    April 4, 2013 at 7:00 pm

    Hi Good Evening..i have downloaded twitter app from here:https://github.com/lorensiuswlt/AndroidTwitter
    here i have to run the app which means the twitter login page is opened.
    i have enter correct login detail means its go to post page..here i have wrote Hi Good morning.afterthat click submit button means thr review posted message is displayed on app.Now i have to check my twitter home page means the data is not posted.
    why the message is didn’t post on home
    please give me solution for these

    Reply
  146. ynmly says

    April 4, 2013 at 11:05 pm

    hey
    i have tried your code..but i am getting only one error in twitterApp.java file in this line
    “mtwitter.setOAuthAccessToken(mAccess)”

    could you plz help me out….i added all jar file

    Reply
  147. scratchdisk says

    April 29, 2013 at 11:38 am

    Thanks for the example app. I did have to update the URLs to get things working. Thanks again.

    mHttpOauthprovider = new DefaultOAuthProvider(“https://api.twitter.com/oauth/request_token”,
    “https://api.twitter.com/oauth/access_token”,
    “https://api.twitter.com/oauth/authorize”);

    Reply
    • Ram says

      July 11, 2013 at 5:28 pm

      Hi,
      i have updated the urls and tokens but i am getting “twitter connection failed” did u resolved the issue ?

      Reply
  148. Bipin says

    July 1, 2013 at 2:31 pm

    Hi,

    I have added all the library into project and it was working perfectly before 11 June 2013, now its showing the error connection failled, can you please sortout this issue,so that we can use the example code further. i think its happening due to change in api from v1 to v1.1.

    Thanks

    Bipin

    Reply
  149. Ram says

    July 8, 2013 at 9:10 pm

    i am getting “twitter connection failed” after updating all the tokens…

    Reply
  150. hatim haffane says

    September 26, 2013 at 8:28 am

    hello
    i import the app and i get this error :

    Invalid request token

    can you please help me?

    Reply
    • Awais says

      November 1, 2013 at 7:16 pm

      if u download it from guihb in that libs folder is missing . Download the jar files and include in your project it’ll work fine

      Reply
  151. Awais says

    November 1, 2013 at 7:14 pm

    Hi,
    Dear admin you have write a very good article , i am using that and working very good. I just want to know the flow , if you can guide me, it would be great help

    Reply
  152. Murali says

    November 27, 2013 at 7:50 pm

    I used latest Twitter4j 3.0.3. But its not working. Its have this error

    11-27 18:15:14.273: W/System.err(1223): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: https://api.twitter.com/oauth/request_token

    Kindly help me

    Reply
  153. janu says

    December 16, 2013 at 7:13 pm

    oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: https://api.twitter.com/oauth/request_tokenKindly help me

    Reply
  154. Mithun says

    January 28, 2014 at 8:14 pm

    Thanks for your tutorial, Its saves my day.
    And can you please tell me how to get user data like User Full name, email address etc.
    Thanks in advance.

    Reply
  155. Anton says

    February 1, 2014 at 4:30 am

    Get “Error getting request token” every time. Consumer key and consumer secret are correct!

    Reply
    • Anton says

      February 1, 2014 at 4:45 am

      I found solution for this problem. Developer must enter request url on dev.twitter.com.

      Reply
      • Robin says

        April 9, 2014 at 8:41 am

        I am having the same problem. What “request url” are you talking about, and where on dev.twitter.com do we enter it?

        Reply
  156. raies says

    February 4, 2014 at 1:52 pm

    i downloaded the code but i’m unable to authroize. when i click on authorize button it redirects me back to first screen and toast a login failed how can i login and post a tweet

    Reply
  157. AKshay Borgave says

    February 18, 2014 at 1:25 pm

    The example helped alot . thanks for posting the code…..

    Reply
    • Android Developer says

      September 15, 2014 at 5:03 pm

      Thank you for you giving this code I am going to use this code.

      Thanks,

      http://www.androdeveloper.com/

      Reply
  158. michael says

    February 19, 2014 at 7:07 pm

    How do you log out the user from twitter?

    Reply
    • Lorensius Londa says

      February 19, 2014 at 9:33 pm

      Don’t need to logout, there is no api for logging out. Just clear the saved access token and webview cache.

      https://dev.twitter.com/discussions/6115

      Reply
  159. suny says

    March 11, 2014 at 10:10 pm

    Having problem with callback url
    i have tried many ways but failed
    talking about mobile app

    after authenticating , it goes to url that i have set on dev.twitter.com rather than coming back to app front page.if i set it to blank then there’s also an error

    i want it to return to app front page …what should i do 🙁
    thnxx

    Reply
    • Lorensius Londa says

      March 14, 2014 at 11:42 am

      Hi suny,

      Please check my new library..hope it helps”

      https://github.com/lorensiuswlt/NewAndroidTwitter

      Reply
  160. Nabeel Ahmed says

    March 18, 2014 at 5:36 pm

    Hi folk,
    I am using your Tutorial, but when I run this on mobile device this gives error “Twitter (Not Connected)”

    I want to get rid this problem please help me soon. . .

    Reply
  161. Jerry Lim says

    May 4, 2014 at 4:50 pm

    Hi, I realized that the posting does not work when there is special character. How can it be resolved? Thansk!

    Reply
  162. Ramesh says

    May 16, 2014 at 6:56 pm

    Hi,
    I’ve downloaded your new library, but i’m unable to get Access Token. I’m getting the following exceptions in log cart. looks like i’ve some problem with Callback URL. can you please help me out.

    05-16 17:19:59.015: W/System.err(6370): java.net.MalformedURLException: Unknown protocol: oauth
    05-16 17:19:59.015: W/System.err(6370): at java.net.URL.(URL.java:288)
    05-16 17:19:59.015: W/System.err(6370): at java.net.URL.(URL.java:157)
    05-16 17:19:59.015: W/System.err(6370): at net.londatiga.android.twitter.TwitterDialog.processVerifier(TwitterDialog.java:152)
    05-16 17:19:59.015: W/System.err(6370): at net.londatiga.android.twitter.TwitterDialog.access$1(TwitterDialog.java:148)
    05-16 17:19:59.015: W/System.err(6370): at net.londatiga.android.twitter.TwitterDialog$TwitterWebViewClient.shouldOverrideUrlLoading(TwitterDialog.java:179)
    05-16 17:19:59.015: W/System.err(6370): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:218)
    05-16 17:19:59.015: W/System.err(6370): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:337)
    05-16 17:19:59.015: W/System.err(6370): at android.os.Handler.dispatchMessage(Handler.java:99)
    05-16 17:19:59.015: W/System.err(6370): at android.os.Looper.loop(Looper.java:130)
    05-16 17:19:59.015: W/System.err(6370): at android.app.ActivityThread.main(ActivityThread.java:3689)
    05-16 17:19:59.015: W/System.err(6370): at java.lang.reflect.Method.invokeNative(Native Method)
    05-16 17:19:59.015: W/System.err(6370): at java.lang.reflect.Method.invoke(Method.java:507)
    05-16 17:19:59.015: W/System.err(6370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    05-16 17:19:59.015: W/System.err(6370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    05-16 17:19:59.015: W/System.err(6370): at dalvik.system.NativeStart.main(Native Method)

    05-16 17:20:02.539: W/ResponseProcessCookies(6370): Invalid cookie header: “set-cookie: guest_id=v1%3A140024100096904543; Domain=.twitter.com; Path=/; Expires=Sun, 15-May-2016 11:50:00 UTC”. Unable to parse expires attribute: Sun, 15-May-2016 11:50:00 UTC
    05-16 17:20:02.546: W/DefaultRequestDirector(6370): Authentication error: Unable to respond to any of these challenges: {oauth=www-authenticate: OAuth realm=”https://api.twitter.com”}
    05-16 17:20:02.546: W/System.err(6370): java.lang.Exception: Unauthorized
    05-16 17:20:02.546: W/System.err(6370): at net.londatiga.android.twitter.oauth.OauthProvider.retreiveAccessToken(OauthProvider.java:207)
    05-16 17:20:02.546: W/System.err(6370): at net.londatiga.android.twitter.Twitter$AccesTokenTask.doInBackground(Twitter.java:222)
    05-16 17:20:02.546: W/System.err(6370): at net.londatiga.android.twitter.Twitter$AccesTokenTask.doInBackground(Twitter.java:1)
    05-16 17:20:02.546: W/System.err(6370): at android.os.AsyncTask$2.call(AsyncTask.java:185)
    05-16 17:20:02.546: W/System.err(6370): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    05-16 17:20:02.546: W/System.err(6370): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    05-16 17:20:02.546: W/System.err(6370): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    05-16 17:20:02.546: W/System.err(6370): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    05-16 17:20:02.546: W/System.err(6370): at java.lang.Thread.run(Thread.java:1019)

    Thanks in advance.

    Reply
  163. Hugo says

    July 11, 2014 at 8:56 pm

    Hello,

    thanks for your work.

    You should use this code for show dialogs for prevent monkey user which spam back button.

    if(!((Activity) context).isFinishing())
    {
    //show dialog
    }

    Regards

    Reply
  164. silambarasan says

    August 18, 2014 at 8:17 pm

    Hi ,

    I am getting unauthorized error.

    Reply
  165. silambarasan says

    August 19, 2014 at 11:24 am

    Hi ,

    I am got below error in using your “New Android-Twitter Library” source code .when i click sign in button got below logcat(error) .kindly let me solution

    08-19 09:49:06.156: W/DefaultRequestDirector(13501): Authentication error: Unable to respond to any of these challenges: {}
    08-19 09:49:06.156: W/System.err(13501): java.lang.Exception: Unauthorized
    08-19 09:49:06.156: W/System.err(13501): at net.londatiga.android.twitter.oauth.OauthProvider.getAuthorizationUrl(OauthProvider.java:121)
    08-19 09:49:06.156: W/System.err(13501): at net.londatiga.android.twitter.Twitter$RequestTokenTask.doInBackground(Twitter.java:166)
    08-19 09:49:06.156: W/System.err(13501): at net.londatiga.android.twitter.Twitter$RequestTokenTask.doInBackground(Twitter.java:1)
    08-19 09:49:06.156: W/System.err(13501): at android.os.AsyncTask$2.call(AsyncTask.java:287)
    08-19 09:49:06.156: W/System.err(13501): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    08-19 09:49:06.156: W/System.err(13501): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    08-19 09:49:06.156: W/System.err(13501): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    08-19 09:49:06.156: W/System.err(13501): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    08-19 09:49:06.156: W/System.err(13501): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    08-19 09:49:06.156: W/System.err(13501): at java.lang.Thread.run(Thread.java:856)

    Reply
  166. Sunil Sunny says

    September 16, 2014 at 9:17 pm

    Hi I am developing an app and I used “https://github.com/lorensiuswlt/NewAndroidTwitter” twitter library for sharing in twitter.It was working perfectly but now it’s not working on Android 4.3(samsung s3),Android 4.1(Sony xperia sl) however it’s working on 4.4 devices(nexus 7 and sony xperia zl).I just debugged the code and it seem’s the issue is caused at the webview.If I am putting a break point on the shouldoverloadingurl method run the step by step it seem’s to work .Guess there is slight timing issue.Do you know anything about it.

    Regards,

    Reply
  167. Arun says

    September 23, 2014 at 1:16 pm

    hi i put Callback URL to display a error on ” mAccessToken = null ”
    how to solve

    Reply
  168. Jeff says

    October 16, 2014 at 4:43 pm

    Thanks for the library, but I’ve a problem. It works in API 19 but not in 16, 17 or 18 since August. It’s very strange.
    I put callbackURL in application as http://www.localhost.com/callback and in the twitter developer http://www.localhost.com

    Could anybody help me?

    Thanks!

    P.D. I tried with the old library, using twitter4j.jar and the result is exactly the same.

    Reply
  169. Jeff says

    October 16, 2014 at 5:16 pm

    Thanks for the library, but I’ve a problem. It works in API 19 but not in 16, 17 or 18 since August. It’s very strange.
    I put the callbackURL in application as http://www.localhost.com/callback and in the twitter developer website http://www.localhost.com

    Could anybody help me?

    Thanks!

    P.D. I tried with the old library, using twitter4j.jar and the result is exactly the same

    Reply
  170. Christina says

    November 17, 2014 at 12:04 am

    Hi!

    Thank you very much for this great work. I had lots of problem finding a starting point for integrating Twitter into my app and this code was a great beginning.

    Thanks again.
    /Christina

    Reply
  171. moza says

    April 5, 2015 at 11:01 pm

    please update it to 4.0.3

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About Me

A husband, father of two, passionate software developer, diy lover and home baker who loves to learn new things. Read More…

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube

Featured Articles

How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Blue Bamboo P25 Printer Android Demo Application With Source Code

Simple JSON RPC Client for Android

How to Send Message to Google Cloud Messaging (GCM) Server Using JSON and PHP

Footer

Recent Comments

  • Aditya Dabas on About
  • Ayten Göksenin Barutçu on How to Make Android Map Scrollable Inside a ScrollView Layout
  • mang jojot on About
  • Hussain on How to Programmatically Scan or Discover Android Bluetooth Devices

Recent Posts

  • How to Fix Blank Screen on WordPress Add/Edit Post Page
  • How to Programmatically Restart the ESP32 Board
  • How to Get Hardware Info of ESP32
  • How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Latest Tweets

  • @tricahyono_bowo @infobandung @infobdg Wah kejauhan om 310 days ago
  • Wilujeng enjing sadayana..Mohon info tempat powder coating dan sandblasting yg recommended di Bandung dunk @infobandung @infobdg314 days ago

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in