我一整天都在尝试将我的应用程序连接到 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 过滤器添加到 list 文件中。但这并不影响结果:
<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 库。
最佳答案
好的,我明白了。我所要做的就是在应用程序的推特页面中插入一个虚拟回调 URL。这种反直觉和丑陋的解决方案。
关于java - Twitter OAuth 回调似乎在 Android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097085/