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

The Archive Base Latest Questions

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

I try to create Twitter client and now I deal with authorization via OAuth

  • 0

I try to create Twitter client and now I deal with authorization via OAuth protocol. I have created “Sign In” button to come in WebView and load twitter authorization URL, that’s work. However, when the authorization is accepted successfuly and Twitter service redirect me to my callback I receive error web page in WebView. That is to say I am not redirected to my activity, I still stay in WebView. But if try the same way via browser, it`s working. What the problem is that?

Main Activivty:

    public class Twitter extends Activity implements OnClickListener {

    Button bSignIn;
    TextView status;
    private OAuthConsumer consumer;
    private OAuthProvider provider;
    private String url;
    final String TAG = getClass().getName();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        bSignIn = (Button) findViewById(R.id.bSignIn);
        status = (TextView) findViewById(R.id.tvStatus);
        bSignIn.setOnClickListener(this);
    }

    public void onClick(View v) {
        new OAuthWebViewProcess().execute();
    }

    public class OAuthWebViewProcess extends AsyncTask<Void, Void, Void> {
        ProgressDialog dialog;

        protected void onPreExecute() {
            dialog = ProgressDialog.show(Twitter.this, null,
                    "Connecting, please wait...");
        }

        protected Void doInBackground(Void... params) {
            try {
            consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
                    Constants.CONSUMER_SECRET);
            provider = new CommonsHttpOAuthProvider(Constants.REQUEST_URL,
                    Constants.ACCESS_URL, Constants.AUTHORIZE_URL);
            url = provider.retrieveRequestToken(consumer,
                        Constants.OAUTH_CALLBACK_URL);
            } catch (Exception e) {
                Log.e(TAG, "Error during OAUth retrieve request token", e);
            }
            return null;
        }

        protected void onPostExecute(Void result) {
            //Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            Intent i = new Intent(Twitter.this, TwitterWebView.class);
            i.putExtra("url", Uri.parse(url).toString());
            startActivityForResult(i, 1);
            dialog.dismiss();
        }
    }
}

WebView for Twitter:

 public class TwitterWebView extends Activity {

    String url;
    WebView TwitterWebView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.twitterwebview);

        Bundle extras = getIntent().getExtras();
        url = extras.getString("url");

        try {
            TwitterWebView = (WebView) findViewById(R.id.wvTwitter);
            TwitterWebView.setWebViewClient(new TwitterWebViewClient(){
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            });
            TwitterWebView.getSettings().setJavaScriptEnabled(true);
            TwitterWebView.getSettings().setDomStorageEnabled(true);
            TwitterWebView.getSettings().setSavePassword(false);
            TwitterWebView.getSettings().setSaveFormData(false);
            TwitterWebView.getSettings().setSupportZoom(false);
            TwitterWebView.loadUrl(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wixanz.app.twitter"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Twitter"
        android:label="@string/app_name"
        android:launchMode="singleInstance" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TwitterWebView"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TweetList"
        android:label="TweetList"
        android:launchMode="singleInstance" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="callback"
                android:scheme="twitter" />
        </intent-filter>
    </activity>
</application>

</manifest>
  • 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-03T05:07:41+00:00Added an answer on June 3, 2026 at 5:07 am

    I did the same about others networks like LinkedIn, Foursquare. But instead of use the callback URL, I override the method shouldOverrideUrlLoading (WebView view, String url) in your WebViewClient (which is used to show the login page) to catch the access token and the token secret (if needed) by myself.

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

Sidebar

Related Questions

I'm looking at implementing an app getting Twitter authorization via Oauth in Java. The
I have a twitter feed and I create a new date obj so I
I have a URL for a twitter feed and I have created a string
I have created a twitter connection with PHP. Everything is fine until I click
I have a user id from a synced contact, I now try to retrieve
I'm trying to implement a Twitter authentication via OAuth on my Django application, but
I have created this php script, to create an xml-file from my database: <?php
I have the following code: try { //Create connection SQLiteConnection conn = DBConnection.OpenDB(); //Verify
I want to try create something like Zend's Server Pagecache. What I want to
I try to create a progress bar that displays the progress of a parser

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.