API do Twitter retorna retorno de chamada inválido - não é possível autorizar

[RESOLVIDO, mas estou aberto a novas sugestões ...]

Estou integrando o Twitter no meu aplicativo Android usando twitter4j.

Quando tento autorizar com o Twitter, estou chamando o endpoint a seguir com meu token oauth:

https://api.twitter.com/oauth/authenticate?oauth_token=MY_VALID_TOKEN

qualdevemos me redirecione para:

MY-CALLBACK:///?oauth_token=***&oauth_verifier=***

mas em vez disso, ele me redireciona para:

https://api.twitter.comMY-CALLBACK///?oauth_token=***&oauth_verifier=***

o que obviamente não é um URL válido.
(Também o: está faltando - deve serMY-CALLBACK:///...)

Por favor, note que estou usando o WebView para minhas chamadas


Eu poderia manipular essa string para fazer tudo funcionar, mas tem que haver uma maneira melhor ...



Estou passando meu URL de retorno de chamada para

getOAuthRequestToken("MY-CALLBACK:///");

e já defini o filtro de intenção para minha atividade com

<data android:scheme="x-oauthflow-twitter" />

Além disso, a atividade temandroid:launchMode="singleInstance"



O que estou fazendo de errado?


[editar: mais detalhes]

mTwitter = new TwitterFactory().getInstance();
mTwitter.setOAuthConsumer(Constants.TWITTER_CONSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET);

twitterWebView = new WebView(ActivityTwitterAuthorize.this);

twitterWebView.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith(Constants.TWITTER_CALLBACK_URL)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);

        // HACKY PART!
        // I added the following code to force it to work, but this is a dirty hack...
        // String TWITTER_CALLBACK_INVALID_PREFIX = "https://api.twitter.comx-oauthflow-twitter///";
        // TWITTER_CALLBACK_URL = "MY-CALLBACK:///";
        // BEGIN
        } else if (url.startsWith(TWITTER_CALLBACK_INVALID_PREFIX)) {
            url = url.substring(TWITTER_CALLBACK_INVALID_PREFIX.length());
            url = Constants.TWITTER_CALLBACK_URL + url;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
        // END

        } else {
            view.loadUrl(url);
        }
        return true;
    }

});

mTwitterReqToken = mTwitter.getOAuthRequestToken(Constants.TWITTER_CALLBACK_URL);

twitterWebView.loadUrl(mTwitterReqToken.getAuthenticationURL());

SEM a parte hacky, esse código resulta em um erro "Página da Web não disponível", porque a URL é inválida:

https://api.twitter.comMY-CALLBACK///?oauth_token=***&oauth_verifier=***

Se o URL foiMY-CALLBACK:///?oauth_token=***&oauth_verifier=*** então minha atividade receberia uma intenção, e tudo ficaria bem ...

COM o "hacky part", meu código funciona, mas eu gostaria de evitar esse pedaço de código.

questionAnswers(4)

yourAnswerToTheQuestion