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

  • SEARCH
  • Home
  • 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 7880319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:07:02+00:00 2026-06-03T04:07:02+00:00

I am using twitter4j in my application. I am using below code to check

  • 0

I am using twitter4j in my application. I am using below code to check if auth token expired or user not logged in yet

public static boolean isAuthenticated(Context context) {

        TwitterPrefrences twitterPref = new TwitterPrefrences(context);     
        String token = twitterPref.getTwitterAuthToken();
        String secret = twitterPref.getTwitterAuthTokenSecrate();

        AccessToken a = new AccessToken(token,secret);
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(Constants.TWITT_CONSUMER_KEY, Constants.TWITT_CONSUMER_SECRET);
        twitter.setOAuthAccessToken(a);

        try {
            twitter.getAccountSettings();
            return true;
        } catch (TwitterException e) {
            return false;
        }

    }

But I am getting following error

 05-02 19:52:23.531: E/AndroidRuntime(1441): FATAL EXCEPTION: main
    05-02 19:52:23.531: E/AndroidRuntime(1441): android.os.NetworkOnMainThreadException
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:45)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:178)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:75)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:103)
    05-02 19:52:23.531: E/AndroidRuntime(1441):     at 

twitter4j.Twitter.getAccountSettings(Twitter.java:1440)

Caller code as

chbTwOption.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked) {
                    boolean showTwlogin = false;
                    if ("No".equalsIgnoreCase(twitPref.getTwitterAuthToken())
                            || "No".equalsIgnoreCase(twitPref.getTwitterAuthTokenSecrate())) {
                        showTwlogin = true;
                    } else {                        
                        showTwlogin = TwitterUtils.isAuthenticated(AddSchedule.this);
                    }   

                    if(showTwlogin) {
                        showSocialMediaLoginMessage(Constants.TW_LOGIN_MESSAGE);
                    }
                }
            }
        });

Its clear that I have to implement AsyncTask for twitter.getAccountSettings() but how can I get result as a method from AsyncTask? Is there any other way to check auth token expire? Or how can I implement AsyncTask as a method which will return result as isAuthenticated() as I used.

Please guide me.

Thank you.

  • 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-03T04:07:03+00:00Added an answer on June 3, 2026 at 4:07 am

    You may have a look at the source for Zwitscher
    and here especially at TwitterLoginActivity

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

Sidebar

Related Questions

I'm updating my user's Twitter status using the simple code below. My problem is
I am using an application to authorize a user in Twitter using Twitter4j library.
I am using Twitter4J API on GAE/J. I want to use the request token
I'm developing Twitter application with xAuth support using twitter4j jar file. I want to
I'm developing Android application using third party libraries (Twitter4j). I want to be able
I'm retrieving some data from Twitter using the code below Dim FilterData = follow=13,15
i am making a twitter client (desktop application) in Java, i am using twitter4j
Hey. I am developing an application using the Twitter4j api. In order to allow
I am using twitter4j to send tweet from my application. When I invoke the
Can User follow up on twitter using iphone application. I have done the functionality

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.