Android Jtwitter,身份验证问题

时间:2011-07-22 14:46:31

标签: android authentication twitter oauth-2.0 jtwitter

您好我使用JTwitter功能无法通过我的Twitter应用程序进行身份验证。我总是得到一个“TwitterException”

这是我的方法

OAuthSignpostClient oauthClient = new OAuthSignpostClient(consumerKey, 
            privateKey, "oob");

a)我不知道“oob”值应该是什么,它是“callbackURL”,在我的Twitter上的应用程序中它说"callBack URL: none"所以我尝试了"none",{ {1}}和"None"其中null没有任何不同的结果。

然后其余的是样板

"oob"

此时,我根本不确定如何使这项工作。希望我对它更加冗长,但它与身份验证有关。我见过的在线内容没有帮助

3 个答案:

答案 0 :(得分:7)

试试 作为回调网址

OAuthSignpostClient oauthClient = 
    new OAuthSignpostClient(consumerKey, privateKey, "callback://twitter");  

记住! 之后:

    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));

执行以下操作

覆盖 onResume()以获取验证码

protected void onResume() {
    super.onResume();
    if (this.getIntent()!=null && this.getIntent().getData()!=null){
        Uri uri = this.getIntent().getData();
        if (uri != null && uri.toString().startsWith("callback://twitter")) {
            //Do whatever you want
            //usually use uri.getQueryParameter(someString);
            //test what could be someString using Log.v("",uri.toString());
            //you want the Authorization code which is a couple of numbers
            //so you could use oauthClient.setAuthorizationCode(v); 
            //and finally initialise Twitter
        }
    }
}

您可以使用uri.getQueryParameterNames()获取参数String


@BobVork

我想补充一点,您需要在Twitter应用的“设置”标签中设置一个回调网址(在twitter.com上)。

你在场上放什么都没关系,但是如果它是空的,回调网址将不起作用。

答案 1 :(得分:1)

我不确定这是不是问题,但似乎你从未为twitter对象设置用户名。

答案 2 :(得分:1)

好吧,我不知道它是如何使用Jtwitter API而我现在还不知道足够的Java来真正理解这段代码的内部工作原理,但是你试过了,而不是NULLNone代替尝试?。这是从Javascript调用时与restful API一起使用的回调。尝试一下。