1

我整天都在尝试将我的应用程序连接到 android,但我没有运气。我一直在寻找几个小时,但我找到的所有资源要么不完整,要么已经过时。到目前为止我有这个:

private class MyAsync extends AsyncTask<Void, Void, AccessToken> {

    @Override
    protected AccessToken doInBackground(Void... params) {
        try {
            requestToken = twitter.getOAuthRequestToken();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(requestToken.getAuthorizationURL()));
            startActivity(browserIntent);
        } catch (TwitterException e) {

            e.printStackTrace();
        }
        Log.d("token", "here1");
        return token;
    }

}

就打开授权页面而言,上述方法有效。但是,当我添加回调 URL(如下所示)时,应用程序停止工作。它甚至不再打开浏览器:

twitter.getOAuthRequestToken("myapp://callback");

我在某处读到我应该将以下意图过滤器添加到清单文件中。但这并不影响结果:

        <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="myapp" android:host="callback" />
        </intent-filter>

如果有帮助,我正在使用 twitter4j 库。

4

1 回答 1

1

好,我知道了。我所要做的就是在应用程序的推特页面中插入一个虚拟回调 URL。这种反直觉和丑陋的解决方案。

于 2012-12-31T15:33:04.407 回答