微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android Twitter集成 – 卡在登录页面?

我有一个以前的Android应用程序的代码,我成功地与Twitter集成.我已将此代码复制到新应用程序并更改了我的新应用程序的callback-url,consumer-key和consumer-secret.

使用twitter4j库我可以获得我的RequestToken和身份验证URL,如下所示:

Twitter twitter = new TwitterFactory().getInstance();
twitter.setoAuthConsumer(myConsumerKey, myConsumerSecret);
RequestToken requestToken = twitter.getoAuthRequestToken(myCallbackUrl);
String authenticationUrl = requestToken.getAuthenticationURL()

RequestToken具有非空令牌值,非null tokenSecret值和null secretKeySpec值.身份验证网址格式如下:

http://api.twitter.com/oauth/authenticate?oauth_token=...

我在我的WebView中加载此URL,我看到以下页面

在这里,我被困住了.当我单击“登录”按钮时,只是同一页面继续加载.没有其他的.当我单击取消按钮时,我看到以下页面

只有在这页面上,当我点击返回粉丝联盟Beko BBL按钮是我的callback-url被调用,带有被拒绝的参数,其中我的oauth_token为其值.之前有人看过这样的东西,知道什么可能阻止我的签名请求被处理???

Update 1: I’ve tried the authentication url and the Sign In button from a desktop browser and it works as expected, processing the response and then invoking the callback-url. It’s just failing when trying it in the WebView of my Android app. I’ve tried it on multiple Android devices and tablets. JavaScript is enabled on my WebView too so that’s not it. Ideas most welcome. I’m out of ideas!

Update 2: I’ve just done some debug-mode code-tracing on my WebView‘s WebViewClient and I’m seeing that when I click the Sign In button, the shouldOverrideUrlLoading(WebView webView, String url) method is not called, but the following three methods are called (in order): onPageStarted(WebView view, String url, Bitmap favicon), onLoadResource(WebView view, String url), onPageFinished(WebView view, String url). The url value these methods have is: https://api.twitter.com/oauth/authenticate, i.e. the oauth_token parameter has been stripped off the authenticate url. Maybe this is a POST request being treated as a GET request and hence why this one same page keeps loading up? Any ideas what I can do to have this Sign In button press processed properly?

解决方法:

我想你忘了从twitter app控制面板设置一个回调网址.

登录twitter api部分,选择您的应用程序并转到设置选项卡.

如果不这样做,当用户按下登录时,不会发生重定向,因此您将无法捕获验证程序.

另一方面,当您设置回调网址时,您的网页视图可以拦截重定向.

注意:您可以设置您想要的任何URL,重要的是捕获传递给重定向URL的oauth_verifier参数.

在那种情况下你的

shouldOverrideUrlLoading

应该被触发.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐