logo logo

How to Post Twitter Status from Android

Home » Information Technology » Programming » Android » How to Post Twitter Status from Android

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 it’s token and username on shared preferences so it can be used later to post status to Twitter.

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.

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

Share
Related post:
bottom

257 Responses to “How to Post Twitter Status from Android”

  1. veljko says:

    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?

    • lorenz says:

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

      • veljko says:

        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.

        • lorenz says:

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

          • veljko says:

            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.

    • 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. :)

  2. Prayag says:

    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

  3. Nicolas says:

    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.

  4. Nirav says:

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

  5. Yashpal says:

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

  6. Andrea says:

    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.

  7. Prayag says:

    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

    • lorenz says:

      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.

  8. bharadwaj says:

    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….

  9. bharadwaj says:

    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…

    • lorenz says:

      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”);

  10. 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? ?

  11. jatin says:

    hi its shows twitter connection failed

    • jatin says:

      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=0×10000000 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

  12. Payal says:

    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.

  13. Payal says:

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

    thanks in advance

  14. Huseyin says:

    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…

  15. Huseyin says:

    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…

  16. Kaushal Sharma says:

    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

  17. Aaron says:

    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

    • Aaron says:

      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

    • lorenz says:

      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?

  18. Doularam says:

    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

  19. Doularam says:

    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.

  20. Shreyash says:

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

  21. Amanda says:

    Hi lorenz,

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

    Please advice.

    Thank you!

    • lorenz says:

      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”);

  22. Jeff Jolley says:

    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.

  23. Ahariss says:

    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.

  24. An=kur says:

    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

  25. Ankur says:

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

  26. sahil says:

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

  27. Ian Morgan says:

    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.

    • lorenz says:

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

      • Dave Wagler says:

        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.

        • lorenz says:

          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.

        • Dave Wagler says:

          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.

  28. Ian Morgan says:

    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.

  29. Willy says:

    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

    • Willy says:

      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

    • lorenz says:

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

  30. Dawid says:

    I am getting blank page in autorization.

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

  31. Tweets says:

    New to integration of twitter.

    Could you provide link for downloading sample project also

  32. Eddy Faustor says:

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

  33. yogi says:

    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

  34. TheTime says:

    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”);

  35. Addy says:

    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

  36. Tariq says:

    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.

  37. dinu says:

    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

  38. dinu says:

    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.

  39. Punit says:

    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

  40. MAC says:

    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

  41. MAC says:

    message :P ost 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.

  42. Tjay says:

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

  43. Tjay says:

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

  44. Rooban Ponraj says:

    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)

  45. Amit Tiwari says:

    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

  46. Amit Tiwari says:

    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

  47. Rommy says:

    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???

  48. MIP TECH says:

    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 0×22 at 0×000c
    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 0×6e at 0×000a
    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 0×6e at 0×0002
    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 0×6
    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 0×0d at 0×0006
    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=0×4001b188)
    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 0×22 at 0×000c
    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 0×6e at 0×000a
    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 0×6e at 0×0002
    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 0×6
    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 0×0d at 0×0006
    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

  49. ramesh says:

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

  50. Hi Lorenze,

    Thanks for the post. It helped me a lot.

Leave a Reply

 
bottom