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 8658741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:50:31+00:00 2026-06-12T15:50:31+00:00

public class TwitterActivity extends Activity { private Twitter twitter; private OAuthProvider provider; private CommonsHttpOAuthConsumer

  • 0
 public class TwitterActivity extends Activity 
    {
        private Twitter twitter;
        private OAuthProvider provider;
        private CommonsHttpOAuthConsumer consumer;

        String CONSUMER_KEY = "abcdefgh";
        String CONSUMER_SECRET = "abcdefgh";
        String CALLBACK = "twitterapp://connect"; 


        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            askOAuth();
        }

        private void askOAuth() {
            try {
                consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
                provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token",
                                                    "http://twitter.com/oauth/access_token",
                                                    "http://twitter.com/oauth/authorize");
                String authUrl = provider.retrieveRequestToken(consumer, CALLBACK);
                Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
                this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
            } catch (Exception e) {
                Log.e(APP, e.getMessage());
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        protected void onNewIntent(Intent intent) {

            super.onNewIntent(intent);

            Uri uri = intent.getData();
            if (uri != null && uri.toString().startsWith(CALLBACK)) {

                String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);

                try {
                    // this will populate token and token_secret in consumer
                    provider.retrieveAccessToken(consumer, verifier);

                    // TODO: you might want to store token and token_secret in you app settings!!!!!!!!
                    AccessToken a = new AccessToken(consumer.getToken(), consumer.getTokenSecret());

                    // initialize Twitter4J
                    twitter = new TwitterFactory().getInstance();
                    twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
                    twitter.setOAuthAccessToken(a);

                    // create a tweet
                    Date d = new Date(System.currentTimeMillis());
                    String tweet = "#OAuth working! " + d.toLocaleString();

                    // send the tweet
                    twitter.updateStatus(tweet);

                } catch (Exception e) {
                    Log.e(APP, e.getMessage());
                    Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }
    }


P.S.: I have used these api's 
  [1]: https://github.com/punitmg/Twitter-Test-App
  [2]: https://github.com/grantland/twitter-android-sdk
  [3]: https://github.com/yusuke/twitter4j/  

By using all these API’s i am able to tweet successfully. But unfortunately the below mentioned 2 screens are appearing in all the above 3 cases..

All i want is to finish() or close the below two screen when my tweet is completed.

So .... plz guide me if i was wrong ... 

screenshot1

screenshot2

  • 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-12T15:50:32+00:00Added an answer on June 12, 2026 at 3:50 pm

    You need to force login second time to resolve this issue,

    So just add the force_login=true in your twitter authorize url.

    I mean just change the below line of code in TwitterApp.java class (if you have a class file with different name then search in your project with DefaultOAuthProvider)

    mHttpOauthprovider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token",
                    "http://twitter.com/oauth/access_token",
            "http://twitter.com/oauth/authorize?force_login=true");
    

    after adding force_login=true webview loading issue will be resolve but every time you need to enter login and password.

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

Sidebar

Related Questions

public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class FBPost extends Service{ private Bundle params = new Bundle(); private String userID=;
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class Bird { private static int id = 0; private String kind; public
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class GenericDao <T, PK extends Serializable> { private final Class<T> type; @Resource(name =

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.