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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:26+00:00 2026-06-10T16:56:26+00:00

My aim is to allow Twitter logins using twitter4j. I used this as reference.

  • 0

My aim is to allow Twitter logins using twitter4j. I used this as reference.

The problem is that at line 64, it calls getAuthenticationURl(). When I execute it takes me to the login page, instead of the page where I can allow/disallow my app access to the ppl’s account.
However, if I change it to getAuthorizationUrl() it takes to the correct page.

1) So what is the difference between the two?

2) This is the important question. I am providing the code below.

package com.example.twitter;



import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.http.AccessToken;
import twitter4j.http.RequestToken;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class WriteTweet extends Activity{
    public final static String consumerKey = "xxxxxxxxxxxxxxxxxx";
    public final static String consumerSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    private final String CALLBACKURL = "T4J_OAuth://callback";
    Twitter twitter;
    RequestToken requestToken;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        loginUser();
    }

    private void loginUser() {
        // TODO Auto-generated method stub
        try {
            twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer(consumerKey, consumerSecret);
            requestToken = twitter.getOAuthRequestToken(CALLBACKURL);
            String authUrl = requestToken.getAuthorizationURL();
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
                    .parse(authUrl)));
        } catch (TwitterException ex) {
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
            Log.e("in Main.OAuthLogin", ex.getMessage());
        }
    }
    @Override
    protected void onNewIntent(Intent intent) {
        Log.e("hi","hi");
        super.onNewIntent(intent);
        Uri uri = intent.getData();
        try {
            String verifier = uri.getQueryParameter("oauth_verifier");
            AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,
                    verifier);
            String token = accessToken.getToken(), secret = accessToken
                    .getTokenSecret();
            displayTimeLine(token, secret); //after everything, display the first tweet 

        } catch (TwitterException ex) {
            Log.e("Main.onNewIntent", "" + ex.getMessage());
        }

    }
    @SuppressWarnings("deprecation")
    void displayTimeLine(String token, String secret) {
        Log.e("display","timeline");
    }

}

the manifest is

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.twitter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application

        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>


        <activity android:name=".ListTweets" >

        </activity>
        <activity android:name=".WriteTweet"> 
                <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:scheme="T4J_OAuth" android:host="callback" />
                </intent-filter>
        </activity>
        <activity android:name=".ViewFollowers">

        </activity>
    </application>

</manifest>

The problem is that it redirects me to https://mobile.twitter.com/
and I cant figure out what am doing wrong. The problem exist no matter if whether getAuthenticationUrl() or getAuthorizationUrl() is used. I had provided a dummy url in the callback_url field in Twitter.
If I didn’t provide a callbackurl in code and in the twitter page it will give me a pin number. But that is not what I want. I need my twitter to redirect to my app. How can I achieve this?

  • 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-10T16:56:27+00:00Added an answer on June 10, 2026 at 4:56 pm

    This is the way I got around the problem,

    1. create a web-view and load the conformation page of twitter from within your app.

      vw = (WebView)findViewById(R.id.loginView);
      vw.setWebViewClient(new WebViewClient() {
          @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
              return super.shouldOverrideUrlLoading(view, url);
          }
      }); vw.loadUrl(authUrl);
      
    2. Once you receive a callback_url, get the ‘ oauth_verifier ‘

                  Uri uri = Uri.parse(url);
                  String verifier = uri.getQueryParameter("oauth_verifier");
      
    3. Use this verifier to get access and do what you want. In my case I destroy the webview and load the activity I require.

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

Sidebar

Related Questions

My aim is to execute an external executable in my program. First, I used
AIM: I would like to tail the last line of the file.txt and input
AIM: To output the contents of a log file line by line newest at
My aim is to create a map function like this map = function ()
I need to setup a bill pay system to allow for 1 transaction that
I'm implementing a FUSE driver for Google Drive. The aim is to allow a
I am using MOD_REWRITE to channel all URLs through a single file. The aim
I was wondering if there was a particular method that would allow me to
I have a website, where I allow other developers to host content. My aim
Basically, I aim to allow my user to specify an ip range for access

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.