Problema en devolución de llamada en Twitter en Android

He implementado Twitter en mi aplicación, estoy enfrentando un problema en Callback.

API de Twitter se ha actualizado recientemente, por lo que no puedo enviar la URL de devolución de llamada.

También la página de configuración ahora cambia, no hay opción para seleccionar una aplicación basada en web o una aplicación de escritorio.

Si envío una devolución de llamada en esta línea:

authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URL);

Siempre devuelve

oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.

pero si envío comoNul en esto es Redireccionando a la página de inicio de sesión de Twitter, pero después de una Autorización exitosa, no vuelve a mi Aplicación.

Después de que se muestre el número PIN, quiero redirigir de nuevo a mi aplicación.

Nota: Twitter había actualizado su API, por lo que los códigos antiguos disponibles en la publicación no funcionan.

Intenté todos los siguientes enlaces

Link 1, Link 2, Link 3, Link4, Link5, Link 6

Mi código es el siguiente:

public class Main extends Activity {
OAuthConsumer consumer;
OAuthProvider provider;
Twitter twitter;
private static  String CALLBACK_URL = "twitterapptest://connect";


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

    consumer = new DefaultOAuthConsumer(
            "XXXXXXXXXXX",
            "XXXXXXXXXXXXX");

    provider = new DefaultOAuthProvider(
            "https://api.twitter.com/oauth/request_token",
            "https://api.twitter.com/oauth/access_token",
            "https://api.twitter.com/oauth/authorize");

    String authUrl = null;
    try {
        authUrl = provider.retrieveRequestToken(consumer,null);
         this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String pin = null;
    try {
        pin = br.readLine();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        provider.retrieveAccessToken(consumer, "4947222");
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    URL url = null;
    try {
        url = new URL("http://twitter.com/statuses/mentions.xml");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HttpURLConnection request = null;
    try {
        request = (HttpURLConnection) url.openConnection();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        consumer.sign(request);
    } catch (OAuthMessageSignerException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (OAuthExpectationFailedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (OAuthCommunicationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        request.connect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        System.out.println("Response: " + request.getResponseCode() + " "
                + request.getResponseMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


/**
 * As soon as the user successfully authorized the app, we are notified
 * here. Now we need to get the verifier from the callback URL, retrieve
 * token and token_secret and feed them to twitter4j (as well as
 * consumer key and secret).
 */

     @Override
    protected void onNewIntent(Intent intent) {

        super.onNewIntent(intent);

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

            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("XXXXXXX", "XXXXXXXXXX");
                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) {

                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    }
}

Mi manifiesto:

<?xml version="1.0" encoding="utf-8"?>

    <activity android:name=".OAuthForTwitter"  android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden"  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:scheme="twitterapptest" android:host="connect" />
    </intent-filter>

</activity>

</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />

Respuestas a la pregunta(3)

Su respuesta a la pregunta