Android Jtwitter,身份验证问题

发布于 2024-11-25 20:14:42 字数 1416 浏览 1 评论 0原文

您好,我在使用 JTwitter 功能对我的 Twitter 应用程序进行身份验证时遇到困难。我总是得到一个“TwitterException”

这是我的方法

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

a)我不知道“oob”值应该是什么,它是“callbackURL”,在我的Twitter应用程序中它说“callBack URL:none” 所以我尝试将 "none""None"null 放在 "oob" 处> 没有不同的结果。

那么剩下的就是样板

 Intent i = new Intent(Intent.ACTION_VIEW, 
    Uri.parse(oauthClient.authorizeUrl().toString()));
    startActivity(i);
    // get the pin
    String v = oauthClient.askUser("Please enter the verification PIN from Twitter");
    oauthClient.setAuthorizationCode(v);
    // Store the authorisation token details for future use
    String[] accessToken = oauthClient.getAccessToken();
    // Next time we can use new OAuthSignpostClient(OAUTH_KEY, OAUTH_SECRET, 
    //        accessToken[0], accessToken[1]) to avoid authenticating again.

    EditText twitterText = (EditText)findViewById(R.id.twitterText);
    twitterText.getText();

    // Make a Twitter object
    Twitter twitter = new Twitter(null, oauthClient);
    // Print Daniel Winterstein's status
    //System.out.println(twitter.getStatus("winterstein"));
    // Set my status
    twitter.setStatus(twitterText.getText());

文件了,我只是不确定如何使这项工作起作用。希望我能更详细地说,但这与身份验证有关。我在网上看到的东西没有帮助

Hello I am having difficulty using the JTwitter functions to authenticate with my twitter application. I always get a "TwitterException"

Here is my method

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

a) I don't know what the "oob" value SHOULD be, it is the "callbackURL" and in my application on twitter it says "callBack URL: none" so I have tried putting "none", "None", and null where "oob" with no differing results.

then the rest is boilerplate

 Intent i = new Intent(Intent.ACTION_VIEW, 
    Uri.parse(oauthClient.authorizeUrl().toString()));
    startActivity(i);
    // get the pin
    String v = oauthClient.askUser("Please enter the verification PIN from Twitter");
    oauthClient.setAuthorizationCode(v);
    // Store the authorisation token details for future use
    String[] accessToken = oauthClient.getAccessToken();
    // Next time we can use new OAuthSignpostClient(OAUTH_KEY, OAUTH_SECRET, 
    //        accessToken[0], accessToken[1]) to avoid authenticating again.

    EditText twitterText = (EditText)findViewById(R.id.twitterText);
    twitterText.getText();

    // Make a Twitter object
    Twitter twitter = new Twitter(null, oauthClient);
    // Print Daniel Winterstein's status
    //System.out.println(twitter.getStatus("winterstein"));
    // Set my status
    twitter.setStatus(twitterText.getText());

at this point, I'm simply not sure on how to make this work. Wish I could be more verbose about it, but it has something to do with the authentication. Online things I've seen haven't been helpful

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以酷 2024-12-02 20:14:42

尝试作为您的回调网址

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

记住!之后:

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

执行以下操作

覆盖< /em> 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 上)的“设置”选项卡中设置回调 URL。

您在该字段中输入的内容并不重要,但如果该字段为空,则回调 url 将不起作用。

Try this as your callback url:

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

Remember! After:

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

Do the following

override onResume() to get the verification code

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
        }
    }
}

You can use uri.getQueryParameterNames() to get the parameter String names.


@BobVork

I'd just like to add that you'll need to have a callback URL set in the Settings tab for your Twitter app (on twitter.com).

It doesn't even matter what you put in the field, but if it's empty, callback urls will not work.

放我走吧 2024-12-02 20:14:42

我不确定这就是问题所在,但似乎您从未设置 twitter 对象的用户名。

I'm not sure that's the problem, but it seems like you never set the user name for the twitter object.

烟雨扶苏 2024-12-02 20:14:42

好吧,我不知道 Jtwitter API 怎么样,而且我目前对 Java 的了解还不够,无法真正理解这段代码的内部工作原理,但是你尝试过,而不是 NULLNone,尝试使用 ?。这是从 Javascript 进行调用时与 Restful API 一起使用的回调。尝试一下。

Well, I don't know how it is with the Jtwitter API and I don't know enough Java at this point to really understand the inner workings of this code, but have you tried, instead of NULL or None, to try ? instead. That is the callback used with the restful API when making calls from Javascript. Try it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文