Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:35:24+00:00 2026-06-01T09:35:24+00:00

Does anyone have a working example of OAuth authentication for twitter with Android? I

  • 0

Does anyone have a working example of OAuth authentication for twitter with Android? I have tried to use both Twitter4J and SignPost, but I get very strange errors, saying twitter.com is an unknown host. I have understod that there is a problem (under Google Android) with the SignPost library and Android and according to the project’s home-page, the CommonsHttpOAuth* classes shall work.

Here is my SignPost:

private void getReqTokenAndAuthenticateUsingSignPost() {
    String callbackUrl = "twitter-test:///";
    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY,
            CONSUMER_SECRET);
    CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
            "http://twitter.com/oauth/request_token", "http://twitter.com/oauth/access_token",
            "http://twitter.com/oauth/authorize");

    String tokenStr = consumer.getToken();
    String tokenSecretStr = consumer.getTokenSecret();

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    Editor edit = preferences.edit();
    edit.putString(REQ_TOKEN, tokenStr);
    edit.putString(REQ_TOKEN_SECRET, tokenSecretStr);

    try {
        String authUrl = provider.retrieveRequestToken(consumer, callbackUrl);
        Uri authenticationUri = Uri.parse(authUrl);
        startActivity(new Intent(Intent.ACTION_VIEW, authenticationUri));
    } catch (OAuthMessageSignerException e) {
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        e.printStackTrace();
    }

}

and here is my code for Twitter4J:

private void getReqTokenAndAuthenticateUsingTwitter4J() {

    String callbackUrl = "twitter-test:///";
    try {
        // Prepare a request token, based on consumer key and consumer
        // secret
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(CONSUMER_KEY);
        builder.setOAuthConsumerSecret(CONSUMER_SECRET);
        Configuration cfg = builder.build();
        Twitter t = new TwitterFactory(cfg).getInstance();

        RequestToken requestToken = t.getOAuthRequestToken(callbackUrl);
        String tokenStr = requestToken.getToken();
        String tokenSecretStr = requestToken.getTokenSecret();

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        Editor edit = preferences.edit();
        edit.putString(REQ_TOKEN, tokenStr);
        edit.putString(REQ_TOKEN_SECRET, tokenSecretStr);
        if (edit.commit()) {
            // Launch the browser for authentication in twitter's web-gui
            Uri authenticationUri = Uri.parse(requestToken.getAuthenticationURL());
            startActivity(new Intent(Intent.ACTION_VIEW, authenticationUri));
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}

and yes, I have a manifest with Internet permission and an intent filter for the callback-url. Here is the output from logcat when running the SignPost code:

W/System.err(  779): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: twitter.com
W/System.err(  779):    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
W/System.err(  779):    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
W/System.err(  779):    at com.examples.twitterimages.TwitterImagesActivity.getReqTokenAndAuthenticateUsingSignPost(TwitterImagesActivity.java:109)
W/System.err(  779):    at com.examples.twitterimages.TwitterImagesActivity.onCreate(TwitterImagesActivity.java:64)
W/System.err(  779):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err(  779):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
W/System.err(  779):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
W/System.err(  779):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
W/System.err(  779):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
W/System.err(  779):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(  779):    at android.os.Looper.loop(Looper.java:123)
W/System.err(  779):    at android.app.ActivityThread.main(ActivityThread.java:3701)
W/System.err(  779):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(  779):    at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err(  779):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
W/System.err(  779):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
W/System.err(  779):    at dalvik.system.NativeStart.main(Native Method)
W/System.err(  779): Caused by: java.net.UnknownHostException: twitter.com
W/System.err(  779):    at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
W/System.err(  779):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
W/System.err(  779):    at java.net.InetAddress.getAllByName(InetAddress.java:256)
W/System.err(  779):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
W/System.err(  779):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err(  779):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err(  779):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
W/System.err(  779):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(  779):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(  779):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(  779):    at oauth.signpost.commonshttp.CommonsHttpOAuthProvider.sendRequest(CommonsHttpOAuthProvider.java:64)
W/System.err(  779):    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)
W/System.err(  779):    ... 16 more

and here is the output when running the Twitter4J code:

W/System.err(  817): api.twitter.comRelevant discussions can be on the Internet at:
W/System.err(  817):    http://www.google.co.jp/search?q=6c607809 or
W/System.err(  817):    http://www.google.co.jp/search?q=0f1d8134
W/System.err(  817): TwitterException{exceptionCode=[6c607809-0f1d8134 6c607809-0f1d810a], statusCode=-1, retryAfter=0, rateLimitStatus=null, version=2.2.1}
W/System.err(  817):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:204)
W/System.err(  817):    at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
W/System.err(  817):    at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
W/System.err(  817):    at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:108)
W/System.err(  817):    at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:271)
W/System.err(  817):    at com.examples.twitterimages.TwitterImagesActivity.getReqTokenAndAuthenticateUsingTwitter4J(TwitterImagesActivity.java:136)
W/System.err(  817):    at com.examples.twitterimages.TwitterImagesActivity.onCreate(TwitterImagesActivity.java:64)
W/System.err(  817):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err(  817):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
W/System.err(  817):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
W/System.err(  817):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
W/System.err(  817):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
W/System.err(  817):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(  817):    at android.os.Looper.loop(Looper.java:123)
W/System.err(  817):    at android.app.ActivityThread.main(ActivityThread.java:3701)
W/System.err(  817):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(  817):    at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err(  817):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
W/System.err(  817):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
W/System.err(  817):    at dalvik.system.NativeStart.main(Native Method)
W/System.err(  817): Caused by: java.net.UnknownHostException: api.twitter.com
W/System.err(  817):    at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
W/System.err(  817):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
W/System.err(  817):    at java.net.InetAddress.getAllByName(InetAddress.java:256)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
W/System.err(  817):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:614)
W/System.err(  817):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
W/System.err(  817):    ... 19 more

Have anybody resolved this? I’m stuck here. I can get the code to run as a Java SE program, but it fails on android…

// Jonas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:35:26+00:00Added an answer on June 1, 2026 at 9:35 am

    Check and Confirm Two Things –

    1-Give Callback URL in Your twitter app created by you on twitter website (Go to your app-> settings->callback url) Click here

    2-Go to Phone settings then click ‘Date and Time’ and select ‘Automatic’ (Please make sure your device Time Zone and Time,Date all are correct) If your time,Date and Time Zone are not correct then you can not tweet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anyone have a generic working example of the use of the ExpertR9.dll library
Does anyone have a working example of a video player built using Qt phonon?
Does anyone have a working example of a Wordpress menu outputted manually? The one
ref: Dynamic Control ID Does anyone have a working example of creating the ID
I have tried to do this in many ways, but none is working. Does
Does anyone have a working example of importing a local file as a module
Does anyone have a working example of using the new GWT constructs for RequestFactory
Does anyone have a working class or function to create the hashed email that
Does anyone have any useful advice/links to information about working with mp3 files in
Does anyone have an example AUTORUN.INF which can launch an MSI installer automatically when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.